module TD.Data.InputIdentityDocument
  ( InputIdentityDocument(..)    
  , defaultInputIdentityDocument 
  ) 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.InputFile as InputFile

data InputIdentityDocument
  = InputIdentityDocument -- ^ An identity document to be saved to Telegram Passport
    { InputIdentityDocument -> Maybe Text
number          :: Maybe T.Text                -- ^ Document number; 1-24 characters
    , InputIdentityDocument -> Maybe Date
expiration_date :: Maybe Date.Date             -- ^ Document expiration date; pass null if not applicable
    , InputIdentityDocument -> Maybe InputFile
front_side      :: Maybe InputFile.InputFile   -- ^ Front side of the document
    , InputIdentityDocument -> Maybe InputFile
reverse_side    :: Maybe InputFile.InputFile   -- ^ Reverse side of the document; only for driver license and identity card; pass null otherwise
    , InputIdentityDocument -> Maybe InputFile
selfie          :: Maybe InputFile.InputFile   -- ^ Selfie with the document; pass null if unavailable
    , InputIdentityDocument -> Maybe [InputFile]
translation     :: Maybe [InputFile.InputFile] -- ^ List of files containing a certified English translation of the document
    }
  deriving (InputIdentityDocument -> InputIdentityDocument -> Bool
(InputIdentityDocument -> InputIdentityDocument -> Bool)
-> (InputIdentityDocument -> InputIdentityDocument -> Bool)
-> Eq InputIdentityDocument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputIdentityDocument -> InputIdentityDocument -> Bool
== :: InputIdentityDocument -> InputIdentityDocument -> Bool
$c/= :: InputIdentityDocument -> InputIdentityDocument -> Bool
/= :: InputIdentityDocument -> InputIdentityDocument -> Bool
Eq, Int -> InputIdentityDocument -> ShowS
[InputIdentityDocument] -> ShowS
InputIdentityDocument -> String
(Int -> InputIdentityDocument -> ShowS)
-> (InputIdentityDocument -> String)
-> ([InputIdentityDocument] -> ShowS)
-> Show InputIdentityDocument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputIdentityDocument -> ShowS
showsPrec :: Int -> InputIdentityDocument -> ShowS
$cshow :: InputIdentityDocument -> String
show :: InputIdentityDocument -> String
$cshowList :: [InputIdentityDocument] -> ShowS
showList :: [InputIdentityDocument] -> ShowS
Show)

instance I.ShortShow InputIdentityDocument where
  shortShow :: InputIdentityDocument -> String
shortShow InputIdentityDocument
    { number :: InputIdentityDocument -> Maybe Text
number          = Maybe Text
number_
    , expiration_date :: InputIdentityDocument -> Maybe Date
expiration_date = Maybe Date
expiration_date_
    , front_side :: InputIdentityDocument -> Maybe InputFile
front_side      = Maybe InputFile
front_side_
    , reverse_side :: InputIdentityDocument -> Maybe InputFile
reverse_side    = Maybe InputFile
reverse_side_
    , selfie :: InputIdentityDocument -> Maybe InputFile
selfie          = Maybe InputFile
selfie_
    , translation :: InputIdentityDocument -> Maybe [InputFile]
translation     = Maybe [InputFile]
translation_
    }
      = String
"InputIdentityDocument"
        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 InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
front_side_
        , String
"reverse_side"    String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
reverse_side_
        , String
"selfie"          String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
selfie_
        , String
"translation"     String -> Maybe [InputFile] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [InputFile]
translation_
        ]

instance AT.FromJSON InputIdentityDocument where
  parseJSON :: Value -> Parser InputIdentityDocument
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
"inputIdentityDocument" -> Value -> Parser InputIdentityDocument
parseInputIdentityDocument Value
v
      String
_                       -> Parser InputIdentityDocument
forall a. Monoid a => a
mempty
    
    where
      parseInputIdentityDocument :: A.Value -> AT.Parser InputIdentityDocument
      parseInputIdentityDocument :: Value -> Parser InputIdentityDocument
parseInputIdentityDocument = String
-> (Object -> Parser InputIdentityDocument)
-> Value
-> Parser InputIdentityDocument
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputIdentityDocument" ((Object -> Parser InputIdentityDocument)
 -> Value -> Parser InputIdentityDocument)
-> (Object -> Parser InputIdentityDocument)
-> Value
-> Parser InputIdentityDocument
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 InputFile
front_side_      <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"front_side"
        Maybe InputFile
reverse_side_    <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"reverse_side"
        Maybe InputFile
selfie_          <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"selfie"
        Maybe [InputFile]
translation_     <- Object
o Object -> Key -> Parser (Maybe [InputFile])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"translation"
        InputIdentityDocument -> Parser InputIdentityDocument
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputIdentityDocument -> Parser InputIdentityDocument)
-> InputIdentityDocument -> Parser InputIdentityDocument
forall a b. (a -> b) -> a -> b
$ InputIdentityDocument
          { number :: Maybe Text
number          = Maybe Text
number_
          , expiration_date :: Maybe Date
expiration_date = Maybe Date
expiration_date_
          , front_side :: Maybe InputFile
front_side      = Maybe InputFile
front_side_
          , reverse_side :: Maybe InputFile
reverse_side    = Maybe InputFile
reverse_side_
          , selfie :: Maybe InputFile
selfie          = Maybe InputFile
selfie_
          , translation :: Maybe [InputFile]
translation     = Maybe [InputFile]
translation_
          }
  parseJSON Value
_ = Parser InputIdentityDocument
forall a. Monoid a => a
mempty

instance AT.ToJSON InputIdentityDocument where
  toJSON :: InputIdentityDocument -> Value
toJSON InputIdentityDocument
    { number :: InputIdentityDocument -> Maybe Text
number          = Maybe Text
number_
    , expiration_date :: InputIdentityDocument -> Maybe Date
expiration_date = Maybe Date
expiration_date_
    , front_side :: InputIdentityDocument -> Maybe InputFile
front_side      = Maybe InputFile
front_side_
    , reverse_side :: InputIdentityDocument -> Maybe InputFile
reverse_side    = Maybe InputFile
reverse_side_
    , selfie :: InputIdentityDocument -> Maybe InputFile
selfie          = Maybe InputFile
selfie_
    , translation :: InputIdentityDocument -> Maybe [InputFile]
translation     = Maybe [InputFile]
translation_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"           Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"inputIdentityDocument"
        , Key
"number"          Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
number_
        , Key
"expiration_date" Key -> Maybe Date -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Date
expiration_date_
        , Key
"front_side"      Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
front_side_
        , Key
"reverse_side"    Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
reverse_side_
        , Key
"selfie"          Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
selfie_
        , Key
"translation"     Key -> Maybe [InputFile] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [InputFile]
translation_
        ]

defaultInputIdentityDocument :: InputIdentityDocument
defaultInputIdentityDocument :: InputIdentityDocument
defaultInputIdentityDocument =
  InputIdentityDocument
    { number :: Maybe Text
number          = Maybe Text
forall a. Maybe a
Nothing
    , expiration_date :: Maybe Date
expiration_date = Maybe Date
forall a. Maybe a
Nothing
    , front_side :: Maybe InputFile
front_side      = Maybe InputFile
forall a. Maybe a
Nothing
    , reverse_side :: Maybe InputFile
reverse_side    = Maybe InputFile
forall a. Maybe a
Nothing
    , selfie :: Maybe InputFile
selfie          = Maybe InputFile
forall a. Maybe a
Nothing
    , translation :: Maybe [InputFile]
translation     = Maybe [InputFile]
forall a. Maybe a
Nothing
    }