module TD.Data.Countries
(Countries(..)) 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.CountryInfo as CountryInfo
data Countries
= Countries
{ Countries -> Maybe [CountryInfo]
countries :: Maybe [CountryInfo.CountryInfo]
}
deriving (Countries -> Countries -> Bool
(Countries -> Countries -> Bool)
-> (Countries -> Countries -> Bool) -> Eq Countries
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Countries -> Countries -> Bool
== :: Countries -> Countries -> Bool
$c/= :: Countries -> Countries -> Bool
/= :: Countries -> Countries -> Bool
Eq, Int -> Countries -> ShowS
[Countries] -> ShowS
Countries -> String
(Int -> Countries -> ShowS)
-> (Countries -> String)
-> ([Countries] -> ShowS)
-> Show Countries
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Countries -> ShowS
showsPrec :: Int -> Countries -> ShowS
$cshow :: Countries -> String
show :: Countries -> String
$cshowList :: [Countries] -> ShowS
showList :: [Countries] -> ShowS
Show)
instance I.ShortShow Countries where
shortShow :: Countries -> String
shortShow Countries
{ countries :: Countries -> Maybe [CountryInfo]
countries = Maybe [CountryInfo]
countries_
}
= String
"Countries"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"countries" String -> Maybe [CountryInfo] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [CountryInfo]
countries_
]
instance AT.FromJSON Countries where
parseJSON :: Value -> Parser Countries
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
"countries" -> Value -> Parser Countries
parseCountries Value
v
String
_ -> Parser Countries
forall a. Monoid a => a
mempty
where
parseCountries :: A.Value -> AT.Parser Countries
parseCountries :: Value -> Parser Countries
parseCountries = String -> (Object -> Parser Countries) -> Value -> Parser Countries
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Countries" ((Object -> Parser Countries) -> Value -> Parser Countries)
-> (Object -> Parser Countries) -> Value -> Parser Countries
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [CountryInfo]
countries_ <- Object
o Object -> Key -> Parser (Maybe [CountryInfo])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"countries"
Countries -> Parser Countries
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Countries -> Parser Countries) -> Countries -> Parser Countries
forall a b. (a -> b) -> a -> b
$ Countries
{ countries :: Maybe [CountryInfo]
countries = Maybe [CountryInfo]
countries_
}
parseJSON Value
_ = Parser Countries
forall a. Monoid a => a
mempty