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