{-# LANGUAGE MultiWayIf #-}
-- CHANGE WITH CAUTION: This is a generated code file generated by https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator.
{-# LANGUAGE OverloadedStrings #-}

-- | Contains the types generated from the schema ExchangeRate
module StripeAPI.Types.ExchangeRate where

import qualified Control.Monad.Fail
import qualified Data.Aeson
import qualified Data.Aeson as Data.Aeson.Encoding.Internal
import qualified Data.Aeson as Data.Aeson.Types
import qualified Data.Aeson as Data.Aeson.Types.FromJSON
import qualified Data.Aeson as Data.Aeson.Types.Internal
import qualified Data.Aeson as Data.Aeson.Types.ToJSON
import qualified Data.ByteString.Char8
import qualified Data.ByteString.Char8 as Data.ByteString.Internal
import qualified Data.Functor
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text.Internal
import qualified Data.Time.Calendar as Data.Time.Calendar.Days
import qualified Data.Time.LocalTime as Data.Time.LocalTime.Internal.ZonedTime
import qualified GHC.Base
import qualified GHC.Classes
import qualified GHC.Int
import qualified GHC.Show
import qualified GHC.Types
import qualified StripeAPI.Common
import StripeAPI.TypeAlias
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.exchange_rate@ in the specification.
--
-- \`Exchange Rate\` objects allow you to determine the rates that Stripe is
-- currently using to convert from one currency to another. Since this number is
-- variable throughout the day, there are various reasons why you might want to
-- know the current rate (for example, to dynamically price an item for a user
-- with a default payment in a foreign currency).
--
-- If you want a guarantee that the charge is made with a certain exchange rate
-- you expect is current, you can pass in \`exchange_rate\` to charges endpoints.
-- If the value is no longer up to date, the charge won\'t go through. Please
-- refer to our [Exchange Rates API](https:\/\/stripe.com\/docs\/exchange-rates) guide for more
-- details.
data ExchangeRate = ExchangeRate
  { -- | id: Unique identifier for the object. Represented as the three-letter [ISO currency code](https:\/\/www.iso.org\/iso-4217-currency-codes.html) in lowercase.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    ExchangeRate -> Text
exchangeRateId :: Data.Text.Internal.Text,
    -- | rates: Hash where the keys are supported currencies and the values are the exchange rate at which the base id currency converts to the key currency.
    ExchangeRate -> Object
exchangeRateRates :: Data.Aeson.Types.Internal.Object
  }
  deriving
    ( Int -> ExchangeRate -> ShowS
[ExchangeRate] -> ShowS
ExchangeRate -> String
(Int -> ExchangeRate -> ShowS)
-> (ExchangeRate -> String)
-> ([ExchangeRate] -> ShowS)
-> Show ExchangeRate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExchangeRate] -> ShowS
$cshowList :: [ExchangeRate] -> ShowS
show :: ExchangeRate -> String
$cshow :: ExchangeRate -> String
showsPrec :: Int -> ExchangeRate -> ShowS
$cshowsPrec :: Int -> ExchangeRate -> ShowS
GHC.Show.Show,
      ExchangeRate -> ExchangeRate -> Bool
(ExchangeRate -> ExchangeRate -> Bool)
-> (ExchangeRate -> ExchangeRate -> Bool) -> Eq ExchangeRate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExchangeRate -> ExchangeRate -> Bool
$c/= :: ExchangeRate -> ExchangeRate -> Bool
== :: ExchangeRate -> ExchangeRate -> Bool
$c== :: ExchangeRate -> ExchangeRate -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON ExchangeRate where
  toJSON :: ExchangeRate -> Value
toJSON ExchangeRate
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= ExchangeRate -> Text
exchangeRateId ExchangeRate
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"rates" Text -> Object -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= ExchangeRate -> Object
exchangeRateRates ExchangeRate
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"object" Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Text -> Value
Data.Aeson.Types.Internal.String Text
"exchange_rate" Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: ExchangeRate -> Encoding
toEncoding ExchangeRate
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"id" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= ExchangeRate -> Text
exchangeRateId ExchangeRate
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"rates" Text -> Object -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= ExchangeRate -> Object
exchangeRateRates ExchangeRate
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"object" Text -> Value -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Text -> Value
Data.Aeson.Types.Internal.String Text
"exchange_rate")))

instance Data.Aeson.Types.FromJSON.FromJSON ExchangeRate where
  parseJSON :: Value -> Parser ExchangeRate
parseJSON = String
-> (Object -> Parser ExchangeRate) -> Value -> Parser ExchangeRate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"ExchangeRate" (\Object
obj -> ((Text -> Object -> ExchangeRate)
-> Parser (Text -> Object -> ExchangeRate)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Text -> Object -> ExchangeRate
ExchangeRate Parser (Text -> Object -> ExchangeRate)
-> Parser Text -> Parser (Object -> ExchangeRate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"id")) Parser (Object -> ExchangeRate)
-> Parser Object -> Parser ExchangeRate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Object
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"rates"))

-- | Create a new 'ExchangeRate' with all required fields.
mkExchangeRate ::
  -- | 'exchangeRateId'
  Data.Text.Internal.Text ->
  -- | 'exchangeRateRates'
  Data.Aeson.Types.Internal.Object ->
  ExchangeRate
mkExchangeRate :: Text -> Object -> ExchangeRate
mkExchangeRate Text
exchangeRateId Object
exchangeRateRates =
  ExchangeRate :: Text -> Object -> ExchangeRate
ExchangeRate
    { exchangeRateId :: Text
exchangeRateId = Text
exchangeRateId,
      exchangeRateRates :: Object
exchangeRateRates = Object
exchangeRateRates
    }