{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SageMaker.Types.USD
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SageMaker.Types.USD where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents an amount of money in United States dollars.
--
-- /See:/ 'newUSD' smart constructor.
data USD = USD'
  { -- | The fractional portion, in cents, of the amount.
    USD -> Maybe Natural
cents :: Prelude.Maybe Prelude.Natural,
    -- | The whole number of dollars in the amount.
    USD -> Maybe Natural
dollars :: Prelude.Maybe Prelude.Natural,
    -- | Fractions of a cent, in tenths.
    USD -> Maybe Natural
tenthFractionsOfACent :: Prelude.Maybe Prelude.Natural
  }
  deriving (USD -> USD -> Bool
(USD -> USD -> Bool) -> (USD -> USD -> Bool) -> Eq USD
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: USD -> USD -> Bool
$c/= :: USD -> USD -> Bool
== :: USD -> USD -> Bool
$c== :: USD -> USD -> Bool
Prelude.Eq, ReadPrec [USD]
ReadPrec USD
Int -> ReadS USD
ReadS [USD]
(Int -> ReadS USD)
-> ReadS [USD] -> ReadPrec USD -> ReadPrec [USD] -> Read USD
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [USD]
$creadListPrec :: ReadPrec [USD]
readPrec :: ReadPrec USD
$creadPrec :: ReadPrec USD
readList :: ReadS [USD]
$creadList :: ReadS [USD]
readsPrec :: Int -> ReadS USD
$creadsPrec :: Int -> ReadS USD
Prelude.Read, Int -> USD -> ShowS
[USD] -> ShowS
USD -> String
(Int -> USD -> ShowS)
-> (USD -> String) -> ([USD] -> ShowS) -> Show USD
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [USD] -> ShowS
$cshowList :: [USD] -> ShowS
show :: USD -> String
$cshow :: USD -> String
showsPrec :: Int -> USD -> ShowS
$cshowsPrec :: Int -> USD -> ShowS
Prelude.Show, (forall x. USD -> Rep USD x)
-> (forall x. Rep USD x -> USD) -> Generic USD
forall x. Rep USD x -> USD
forall x. USD -> Rep USD x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep USD x -> USD
$cfrom :: forall x. USD -> Rep USD x
Prelude.Generic)

-- |
-- Create a value of 'USD' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'cents', 'usd_cents' - The fractional portion, in cents, of the amount.
--
-- 'dollars', 'usd_dollars' - The whole number of dollars in the amount.
--
-- 'tenthFractionsOfACent', 'usd_tenthFractionsOfACent' - Fractions of a cent, in tenths.
newUSD ::
  USD
newUSD :: USD
newUSD =
  USD' :: Maybe Natural -> Maybe Natural -> Maybe Natural -> USD
USD'
    { $sel:cents:USD' :: Maybe Natural
cents = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:dollars:USD' :: Maybe Natural
dollars = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:tenthFractionsOfACent:USD' :: Maybe Natural
tenthFractionsOfACent = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The fractional portion, in cents, of the amount.
usd_cents :: Lens.Lens' USD (Prelude.Maybe Prelude.Natural)
usd_cents :: (Maybe Natural -> f (Maybe Natural)) -> USD -> f USD
usd_cents = (USD -> Maybe Natural)
-> (USD -> Maybe Natural -> USD)
-> Lens USD USD (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\USD' {Maybe Natural
cents :: Maybe Natural
$sel:cents:USD' :: USD -> Maybe Natural
cents} -> Maybe Natural
cents) (\s :: USD
s@USD' {} Maybe Natural
a -> USD
s {$sel:cents:USD' :: Maybe Natural
cents = Maybe Natural
a} :: USD)

-- | The whole number of dollars in the amount.
usd_dollars :: Lens.Lens' USD (Prelude.Maybe Prelude.Natural)
usd_dollars :: (Maybe Natural -> f (Maybe Natural)) -> USD -> f USD
usd_dollars = (USD -> Maybe Natural)
-> (USD -> Maybe Natural -> USD)
-> Lens USD USD (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\USD' {Maybe Natural
dollars :: Maybe Natural
$sel:dollars:USD' :: USD -> Maybe Natural
dollars} -> Maybe Natural
dollars) (\s :: USD
s@USD' {} Maybe Natural
a -> USD
s {$sel:dollars:USD' :: Maybe Natural
dollars = Maybe Natural
a} :: USD)

-- | Fractions of a cent, in tenths.
usd_tenthFractionsOfACent :: Lens.Lens' USD (Prelude.Maybe Prelude.Natural)
usd_tenthFractionsOfACent :: (Maybe Natural -> f (Maybe Natural)) -> USD -> f USD
usd_tenthFractionsOfACent = (USD -> Maybe Natural)
-> (USD -> Maybe Natural -> USD)
-> Lens USD USD (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\USD' {Maybe Natural
tenthFractionsOfACent :: Maybe Natural
$sel:tenthFractionsOfACent:USD' :: USD -> Maybe Natural
tenthFractionsOfACent} -> Maybe Natural
tenthFractionsOfACent) (\s :: USD
s@USD' {} Maybe Natural
a -> USD
s {$sel:tenthFractionsOfACent:USD' :: Maybe Natural
tenthFractionsOfACent = Maybe Natural
a} :: USD)

instance Core.FromJSON USD where
  parseJSON :: Value -> Parser USD
parseJSON =
    String -> (Object -> Parser USD) -> Value -> Parser USD
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"USD"
      ( \Object
x ->
          Maybe Natural -> Maybe Natural -> Maybe Natural -> USD
USD'
            (Maybe Natural -> Maybe Natural -> Maybe Natural -> USD)
-> Parser (Maybe Natural)
-> Parser (Maybe Natural -> Maybe Natural -> USD)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Cents")
            Parser (Maybe Natural -> Maybe Natural -> USD)
-> Parser (Maybe Natural) -> Parser (Maybe Natural -> USD)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Dollars")
            Parser (Maybe Natural -> USD)
-> Parser (Maybe Natural) -> Parser USD
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TenthFractionsOfACent")
      )

instance Prelude.Hashable USD

instance Prelude.NFData USD

instance Core.ToJSON USD where
  toJSON :: USD -> Value
toJSON USD' {Maybe Natural
tenthFractionsOfACent :: Maybe Natural
dollars :: Maybe Natural
cents :: Maybe Natural
$sel:tenthFractionsOfACent:USD' :: USD -> Maybe Natural
$sel:dollars:USD' :: USD -> Maybe Natural
$sel:cents:USD' :: USD -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Cents" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
cents,
            (Text
"Dollars" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
dollars,
            (Text
"TenthFractionsOfACent" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
tenthFractionsOfACent
          ]
      )