{-# 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.DeviceFarm.Types.MonetaryAmount
-- 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.DeviceFarm.Types.MonetaryAmount where

import qualified Amazonka.Core as Core
import Amazonka.DeviceFarm.Types.CurrencyCode
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A number that represents the monetary amount for an offering or
-- transaction.
--
-- /See:/ 'newMonetaryAmount' smart constructor.
data MonetaryAmount = MonetaryAmount'
  { -- | The numerical amount of an offering or transaction.
    MonetaryAmount -> Maybe Double
amount :: Prelude.Maybe Prelude.Double,
    -- | The currency code of a monetary amount. For example, @USD@ means U.S.
    -- dollars.
    MonetaryAmount -> Maybe CurrencyCode
currencyCode :: Prelude.Maybe CurrencyCode
  }
  deriving (MonetaryAmount -> MonetaryAmount -> Bool
(MonetaryAmount -> MonetaryAmount -> Bool)
-> (MonetaryAmount -> MonetaryAmount -> Bool) -> Eq MonetaryAmount
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MonetaryAmount -> MonetaryAmount -> Bool
$c/= :: MonetaryAmount -> MonetaryAmount -> Bool
== :: MonetaryAmount -> MonetaryAmount -> Bool
$c== :: MonetaryAmount -> MonetaryAmount -> Bool
Prelude.Eq, ReadPrec [MonetaryAmount]
ReadPrec MonetaryAmount
Int -> ReadS MonetaryAmount
ReadS [MonetaryAmount]
(Int -> ReadS MonetaryAmount)
-> ReadS [MonetaryAmount]
-> ReadPrec MonetaryAmount
-> ReadPrec [MonetaryAmount]
-> Read MonetaryAmount
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MonetaryAmount]
$creadListPrec :: ReadPrec [MonetaryAmount]
readPrec :: ReadPrec MonetaryAmount
$creadPrec :: ReadPrec MonetaryAmount
readList :: ReadS [MonetaryAmount]
$creadList :: ReadS [MonetaryAmount]
readsPrec :: Int -> ReadS MonetaryAmount
$creadsPrec :: Int -> ReadS MonetaryAmount
Prelude.Read, Int -> MonetaryAmount -> ShowS
[MonetaryAmount] -> ShowS
MonetaryAmount -> String
(Int -> MonetaryAmount -> ShowS)
-> (MonetaryAmount -> String)
-> ([MonetaryAmount] -> ShowS)
-> Show MonetaryAmount
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MonetaryAmount] -> ShowS
$cshowList :: [MonetaryAmount] -> ShowS
show :: MonetaryAmount -> String
$cshow :: MonetaryAmount -> String
showsPrec :: Int -> MonetaryAmount -> ShowS
$cshowsPrec :: Int -> MonetaryAmount -> ShowS
Prelude.Show, (forall x. MonetaryAmount -> Rep MonetaryAmount x)
-> (forall x. Rep MonetaryAmount x -> MonetaryAmount)
-> Generic MonetaryAmount
forall x. Rep MonetaryAmount x -> MonetaryAmount
forall x. MonetaryAmount -> Rep MonetaryAmount x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MonetaryAmount x -> MonetaryAmount
$cfrom :: forall x. MonetaryAmount -> Rep MonetaryAmount x
Prelude.Generic)

-- |
-- Create a value of 'MonetaryAmount' 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:
--
-- 'amount', 'monetaryAmount_amount' - The numerical amount of an offering or transaction.
--
-- 'currencyCode', 'monetaryAmount_currencyCode' - The currency code of a monetary amount. For example, @USD@ means U.S.
-- dollars.
newMonetaryAmount ::
  MonetaryAmount
newMonetaryAmount :: MonetaryAmount
newMonetaryAmount =
  MonetaryAmount' :: Maybe Double -> Maybe CurrencyCode -> MonetaryAmount
MonetaryAmount'
    { $sel:amount:MonetaryAmount' :: Maybe Double
amount = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:currencyCode:MonetaryAmount' :: Maybe CurrencyCode
currencyCode = Maybe CurrencyCode
forall a. Maybe a
Prelude.Nothing
    }

-- | The numerical amount of an offering or transaction.
monetaryAmount_amount :: Lens.Lens' MonetaryAmount (Prelude.Maybe Prelude.Double)
monetaryAmount_amount :: (Maybe Double -> f (Maybe Double))
-> MonetaryAmount -> f MonetaryAmount
monetaryAmount_amount = (MonetaryAmount -> Maybe Double)
-> (MonetaryAmount -> Maybe Double -> MonetaryAmount)
-> Lens MonetaryAmount MonetaryAmount (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MonetaryAmount' {Maybe Double
amount :: Maybe Double
$sel:amount:MonetaryAmount' :: MonetaryAmount -> Maybe Double
amount} -> Maybe Double
amount) (\s :: MonetaryAmount
s@MonetaryAmount' {} Maybe Double
a -> MonetaryAmount
s {$sel:amount:MonetaryAmount' :: Maybe Double
amount = Maybe Double
a} :: MonetaryAmount)

-- | The currency code of a monetary amount. For example, @USD@ means U.S.
-- dollars.
monetaryAmount_currencyCode :: Lens.Lens' MonetaryAmount (Prelude.Maybe CurrencyCode)
monetaryAmount_currencyCode :: (Maybe CurrencyCode -> f (Maybe CurrencyCode))
-> MonetaryAmount -> f MonetaryAmount
monetaryAmount_currencyCode = (MonetaryAmount -> Maybe CurrencyCode)
-> (MonetaryAmount -> Maybe CurrencyCode -> MonetaryAmount)
-> Lens
     MonetaryAmount
     MonetaryAmount
     (Maybe CurrencyCode)
     (Maybe CurrencyCode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MonetaryAmount' {Maybe CurrencyCode
currencyCode :: Maybe CurrencyCode
$sel:currencyCode:MonetaryAmount' :: MonetaryAmount -> Maybe CurrencyCode
currencyCode} -> Maybe CurrencyCode
currencyCode) (\s :: MonetaryAmount
s@MonetaryAmount' {} Maybe CurrencyCode
a -> MonetaryAmount
s {$sel:currencyCode:MonetaryAmount' :: Maybe CurrencyCode
currencyCode = Maybe CurrencyCode
a} :: MonetaryAmount)

instance Core.FromJSON MonetaryAmount where
  parseJSON :: Value -> Parser MonetaryAmount
parseJSON =
    String
-> (Object -> Parser MonetaryAmount)
-> Value
-> Parser MonetaryAmount
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MonetaryAmount"
      ( \Object
x ->
          Maybe Double -> Maybe CurrencyCode -> MonetaryAmount
MonetaryAmount'
            (Maybe Double -> Maybe CurrencyCode -> MonetaryAmount)
-> Parser (Maybe Double)
-> Parser (Maybe CurrencyCode -> MonetaryAmount)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"amount")
            Parser (Maybe CurrencyCode -> MonetaryAmount)
-> Parser (Maybe CurrencyCode) -> Parser MonetaryAmount
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe CurrencyCode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"currencyCode")
      )

instance Prelude.Hashable MonetaryAmount

instance Prelude.NFData MonetaryAmount