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

data InputPersonalDocument
  = InputPersonalDocument -- ^ A personal document to be saved to Telegram Passport
    { InputPersonalDocument -> Maybe [InputFile]
files       :: Maybe [InputFile.InputFile] -- ^ List of files containing the pages of the document
    , InputPersonalDocument -> Maybe [InputFile]
translation :: Maybe [InputFile.InputFile] -- ^ List of files containing a certified English translation of the document
    }
  deriving (InputPersonalDocument -> InputPersonalDocument -> Bool
(InputPersonalDocument -> InputPersonalDocument -> Bool)
-> (InputPersonalDocument -> InputPersonalDocument -> Bool)
-> Eq InputPersonalDocument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputPersonalDocument -> InputPersonalDocument -> Bool
== :: InputPersonalDocument -> InputPersonalDocument -> Bool
$c/= :: InputPersonalDocument -> InputPersonalDocument -> Bool
/= :: InputPersonalDocument -> InputPersonalDocument -> Bool
Eq, Int -> InputPersonalDocument -> ShowS
[InputPersonalDocument] -> ShowS
InputPersonalDocument -> String
(Int -> InputPersonalDocument -> ShowS)
-> (InputPersonalDocument -> String)
-> ([InputPersonalDocument] -> ShowS)
-> Show InputPersonalDocument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputPersonalDocument -> ShowS
showsPrec :: Int -> InputPersonalDocument -> ShowS
$cshow :: InputPersonalDocument -> String
show :: InputPersonalDocument -> String
$cshowList :: [InputPersonalDocument] -> ShowS
showList :: [InputPersonalDocument] -> ShowS
Show)

instance I.ShortShow InputPersonalDocument where
  shortShow :: InputPersonalDocument -> String
shortShow InputPersonalDocument
    { files :: InputPersonalDocument -> Maybe [InputFile]
files       = Maybe [InputFile]
files_
    , translation :: InputPersonalDocument -> Maybe [InputFile]
translation = Maybe [InputFile]
translation_
    }
      = String
"InputPersonalDocument"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"files"       String -> Maybe [InputFile] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [InputFile]
files_
        , String
"translation" String -> Maybe [InputFile] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [InputFile]
translation_
        ]

instance AT.FromJSON InputPersonalDocument where
  parseJSON :: Value -> Parser InputPersonalDocument
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
"inputPersonalDocument" -> Value -> Parser InputPersonalDocument
parseInputPersonalDocument Value
v
      String
_                       -> Parser InputPersonalDocument
forall a. Monoid a => a
mempty
    
    where
      parseInputPersonalDocument :: A.Value -> AT.Parser InputPersonalDocument
      parseInputPersonalDocument :: Value -> Parser InputPersonalDocument
parseInputPersonalDocument = String
-> (Object -> Parser InputPersonalDocument)
-> Value
-> Parser InputPersonalDocument
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputPersonalDocument" ((Object -> Parser InputPersonalDocument)
 -> Value -> Parser InputPersonalDocument)
-> (Object -> Parser InputPersonalDocument)
-> Value
-> Parser InputPersonalDocument
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [InputFile]
files_       <- Object
o Object -> Key -> Parser (Maybe [InputFile])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"files"
        Maybe [InputFile]
translation_ <- Object
o Object -> Key -> Parser (Maybe [InputFile])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"translation"
        InputPersonalDocument -> Parser InputPersonalDocument
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputPersonalDocument -> Parser InputPersonalDocument)
-> InputPersonalDocument -> Parser InputPersonalDocument
forall a b. (a -> b) -> a -> b
$ InputPersonalDocument
          { files :: Maybe [InputFile]
files       = Maybe [InputFile]
files_
          , translation :: Maybe [InputFile]
translation = Maybe [InputFile]
translation_
          }
  parseJSON Value
_ = Parser InputPersonalDocument
forall a. Monoid a => a
mempty

instance AT.ToJSON InputPersonalDocument where
  toJSON :: InputPersonalDocument -> Value
toJSON InputPersonalDocument
    { files :: InputPersonalDocument -> Maybe [InputFile]
files       = Maybe [InputFile]
files_
    , translation :: InputPersonalDocument -> 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
"inputPersonalDocument"
        , Key
"files"       Key -> Maybe [InputFile] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [InputFile]
files_
        , 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_
        ]

defaultInputPersonalDocument :: InputPersonalDocument
defaultInputPersonalDocument :: InputPersonalDocument
defaultInputPersonalDocument =
  InputPersonalDocument
    { files :: Maybe [InputFile]
files       = Maybe [InputFile]
forall a. Maybe a
Nothing
    , translation :: Maybe [InputFile]
translation = Maybe [InputFile]
forall a. Maybe a
Nothing
    }