module TD.Data.CurrencyExchangeRates
(CurrencyExchangeRates(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.CurrencyExchangeRate as CurrencyExchangeRate
data CurrencyExchangeRates
= CurrencyExchangeRates
{ CurrencyExchangeRates -> Maybe [CurrencyExchangeRate]
rates :: Maybe [CurrencyExchangeRate.CurrencyExchangeRate]
}
deriving (CurrencyExchangeRates -> CurrencyExchangeRates -> Bool
(CurrencyExchangeRates -> CurrencyExchangeRates -> Bool)
-> (CurrencyExchangeRates -> CurrencyExchangeRates -> Bool)
-> Eq CurrencyExchangeRates
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CurrencyExchangeRates -> CurrencyExchangeRates -> Bool
== :: CurrencyExchangeRates -> CurrencyExchangeRates -> Bool
$c/= :: CurrencyExchangeRates -> CurrencyExchangeRates -> Bool
/= :: CurrencyExchangeRates -> CurrencyExchangeRates -> Bool
Eq, Int -> CurrencyExchangeRates -> ShowS
[CurrencyExchangeRates] -> ShowS
CurrencyExchangeRates -> String
(Int -> CurrencyExchangeRates -> ShowS)
-> (CurrencyExchangeRates -> String)
-> ([CurrencyExchangeRates] -> ShowS)
-> Show CurrencyExchangeRates
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CurrencyExchangeRates -> ShowS
showsPrec :: Int -> CurrencyExchangeRates -> ShowS
$cshow :: CurrencyExchangeRates -> String
show :: CurrencyExchangeRates -> String
$cshowList :: [CurrencyExchangeRates] -> ShowS
showList :: [CurrencyExchangeRates] -> ShowS
Show)
instance I.ShortShow CurrencyExchangeRates where
shortShow :: CurrencyExchangeRates -> String
shortShow CurrencyExchangeRates
{ rates :: CurrencyExchangeRates -> Maybe [CurrencyExchangeRate]
rates = Maybe [CurrencyExchangeRate]
rates_
}
= String
"CurrencyExchangeRates"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"rates" String -> Maybe [CurrencyExchangeRate] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [CurrencyExchangeRate]
rates_
]
instance AT.FromJSON CurrencyExchangeRates where
parseJSON :: Value -> Parser CurrencyExchangeRates
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"currencyExchangeRates" -> Value -> Parser CurrencyExchangeRates
parseCurrencyExchangeRates Value
v
String
_ -> Parser CurrencyExchangeRates
forall a. Monoid a => a
mempty
where
parseCurrencyExchangeRates :: A.Value -> AT.Parser CurrencyExchangeRates
parseCurrencyExchangeRates :: Value -> Parser CurrencyExchangeRates
parseCurrencyExchangeRates = String
-> (Object -> Parser CurrencyExchangeRates)
-> Value
-> Parser CurrencyExchangeRates
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CurrencyExchangeRates" ((Object -> Parser CurrencyExchangeRates)
-> Value -> Parser CurrencyExchangeRates)
-> (Object -> Parser CurrencyExchangeRates)
-> Value
-> Parser CurrencyExchangeRates
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [CurrencyExchangeRate]
rates_ <- Object
o Object -> Key -> Parser (Maybe [CurrencyExchangeRate])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"rates"
CurrencyExchangeRates -> Parser CurrencyExchangeRates
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CurrencyExchangeRates -> Parser CurrencyExchangeRates)
-> CurrencyExchangeRates -> Parser CurrencyExchangeRates
forall a b. (a -> b) -> a -> b
$ CurrencyExchangeRates
{ rates :: Maybe [CurrencyExchangeRate]
rates = Maybe [CurrencyExchangeRate]
rates_
}
parseJSON Value
_ = Parser CurrencyExchangeRates
forall a. Monoid a => a
mempty