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