module TD.Data.IdentityDocument
(IdentityDocument(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.Date as Date
import qualified TD.Data.DatedFile as DatedFile
data IdentityDocument
= IdentityDocument
{ IdentityDocument -> Maybe Text
number :: Maybe T.Text
, IdentityDocument -> Maybe Date
expiration_date :: Maybe Date.Date
, IdentityDocument -> Maybe DatedFile
front_side :: Maybe DatedFile.DatedFile
, IdentityDocument -> Maybe DatedFile
reverse_side :: Maybe DatedFile.DatedFile
, IdentityDocument -> Maybe DatedFile
selfie :: Maybe DatedFile.DatedFile
, IdentityDocument -> Maybe [DatedFile]
translation :: Maybe [DatedFile.DatedFile]
}
deriving (IdentityDocument -> IdentityDocument -> Bool
(IdentityDocument -> IdentityDocument -> Bool)
-> (IdentityDocument -> IdentityDocument -> Bool)
-> Eq IdentityDocument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IdentityDocument -> IdentityDocument -> Bool
== :: IdentityDocument -> IdentityDocument -> Bool
$c/= :: IdentityDocument -> IdentityDocument -> Bool
/= :: IdentityDocument -> IdentityDocument -> Bool
Eq, Int -> IdentityDocument -> ShowS
[IdentityDocument] -> ShowS
IdentityDocument -> String
(Int -> IdentityDocument -> ShowS)
-> (IdentityDocument -> String)
-> ([IdentityDocument] -> ShowS)
-> Show IdentityDocument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IdentityDocument -> ShowS
showsPrec :: Int -> IdentityDocument -> ShowS
$cshow :: IdentityDocument -> String
show :: IdentityDocument -> String
$cshowList :: [IdentityDocument] -> ShowS
showList :: [IdentityDocument] -> ShowS
Show)
instance I.ShortShow IdentityDocument where
shortShow :: IdentityDocument -> String
shortShow IdentityDocument
{ number :: IdentityDocument -> Maybe Text
number = Maybe Text
number_
, expiration_date :: IdentityDocument -> Maybe Date
expiration_date = Maybe Date
expiration_date_
, front_side :: IdentityDocument -> Maybe DatedFile
front_side = Maybe DatedFile
front_side_
, reverse_side :: IdentityDocument -> Maybe DatedFile
reverse_side = Maybe DatedFile
reverse_side_
, selfie :: IdentityDocument -> Maybe DatedFile
selfie = Maybe DatedFile
selfie_
, translation :: IdentityDocument -> Maybe [DatedFile]
translation = Maybe [DatedFile]
translation_
}
= String
"IdentityDocument"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"number" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
number_
, String
"expiration_date" String -> Maybe Date -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Date
expiration_date_
, String
"front_side" String -> Maybe DatedFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe DatedFile
front_side_
, String
"reverse_side" String -> Maybe DatedFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe DatedFile
reverse_side_
, String
"selfie" String -> Maybe DatedFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe DatedFile
selfie_
, String
"translation" String -> Maybe [DatedFile] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [DatedFile]
translation_
]
instance AT.FromJSON IdentityDocument where
parseJSON :: Value -> Parser IdentityDocument
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
"identityDocument" -> Value -> Parser IdentityDocument
parseIdentityDocument Value
v
String
_ -> Parser IdentityDocument
forall a. Monoid a => a
mempty
where
parseIdentityDocument :: A.Value -> AT.Parser IdentityDocument
parseIdentityDocument :: Value -> Parser IdentityDocument
parseIdentityDocument = String
-> (Object -> Parser IdentityDocument)
-> Value
-> Parser IdentityDocument
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"IdentityDocument" ((Object -> Parser IdentityDocument)
-> Value -> Parser IdentityDocument)
-> (Object -> Parser IdentityDocument)
-> Value
-> Parser IdentityDocument
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
number_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"number"
Maybe Date
expiration_date_ <- Object
o Object -> Key -> Parser (Maybe Date)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"expiration_date"
Maybe DatedFile
front_side_ <- Object
o Object -> Key -> Parser (Maybe DatedFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"front_side"
Maybe DatedFile
reverse_side_ <- Object
o Object -> Key -> Parser (Maybe DatedFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reverse_side"
Maybe DatedFile
selfie_ <- Object
o Object -> Key -> Parser (Maybe DatedFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"selfie"
Maybe [DatedFile]
translation_ <- Object
o Object -> Key -> Parser (Maybe [DatedFile])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"translation"
IdentityDocument -> Parser IdentityDocument
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdentityDocument -> Parser IdentityDocument)
-> IdentityDocument -> Parser IdentityDocument
forall a b. (a -> b) -> a -> b
$ IdentityDocument
{ number :: Maybe Text
number = Maybe Text
number_
, expiration_date :: Maybe Date
expiration_date = Maybe Date
expiration_date_
, front_side :: Maybe DatedFile
front_side = Maybe DatedFile
front_side_
, reverse_side :: Maybe DatedFile
reverse_side = Maybe DatedFile
reverse_side_
, selfie :: Maybe DatedFile
selfie = Maybe DatedFile
selfie_
, translation :: Maybe [DatedFile]
translation = Maybe [DatedFile]
translation_
}
parseJSON Value
_ = Parser IdentityDocument
forall a. Monoid a => a
mempty