module TD.Data.PassportSuitableElement
  (PassportSuitableElement(..)) 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.PassportElementType as PassportElementType

data PassportSuitableElement
  = PassportSuitableElement -- ^ Contains information about a Telegram Passport element that was requested by a service
    { PassportSuitableElement -> Maybe PassportElementType
_type                   :: Maybe PassportElementType.PassportElementType -- ^ Type of the element
    , PassportSuitableElement -> Maybe Bool
is_selfie_required      :: Maybe Bool                                    -- ^ True, if a selfie is required with the identity document
    , PassportSuitableElement -> Maybe Bool
is_translation_required :: Maybe Bool                                    -- ^ True, if a certified English translation is required with the document
    , PassportSuitableElement -> Maybe Bool
is_native_name_required :: Maybe Bool                                    -- ^ True, if personal details must include the user's name in the language of their country of residence
    }
  deriving (PassportSuitableElement -> PassportSuitableElement -> Bool
(PassportSuitableElement -> PassportSuitableElement -> Bool)
-> (PassportSuitableElement -> PassportSuitableElement -> Bool)
-> Eq PassportSuitableElement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PassportSuitableElement -> PassportSuitableElement -> Bool
== :: PassportSuitableElement -> PassportSuitableElement -> Bool
$c/= :: PassportSuitableElement -> PassportSuitableElement -> Bool
/= :: PassportSuitableElement -> PassportSuitableElement -> Bool
Eq, Int -> PassportSuitableElement -> ShowS
[PassportSuitableElement] -> ShowS
PassportSuitableElement -> String
(Int -> PassportSuitableElement -> ShowS)
-> (PassportSuitableElement -> String)
-> ([PassportSuitableElement] -> ShowS)
-> Show PassportSuitableElement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PassportSuitableElement -> ShowS
showsPrec :: Int -> PassportSuitableElement -> ShowS
$cshow :: PassportSuitableElement -> String
show :: PassportSuitableElement -> String
$cshowList :: [PassportSuitableElement] -> ShowS
showList :: [PassportSuitableElement] -> ShowS
Show)

instance I.ShortShow PassportSuitableElement where
  shortShow :: PassportSuitableElement -> String
shortShow PassportSuitableElement
    { _type :: PassportSuitableElement -> Maybe PassportElementType
_type                   = Maybe PassportElementType
_type_
    , is_selfie_required :: PassportSuitableElement -> Maybe Bool
is_selfie_required      = Maybe Bool
is_selfie_required_
    , is_translation_required :: PassportSuitableElement -> Maybe Bool
is_translation_required = Maybe Bool
is_translation_required_
    , is_native_name_required :: PassportSuitableElement -> Maybe Bool
is_native_name_required = Maybe Bool
is_native_name_required_
    }
      = String
"PassportSuitableElement"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_type"                   String -> Maybe PassportElementType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe PassportElementType
_type_
        , String
"is_selfie_required"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_selfie_required_
        , String
"is_translation_required" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_translation_required_
        , String
"is_native_name_required" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_native_name_required_
        ]

instance AT.FromJSON PassportSuitableElement where
  parseJSON :: Value -> Parser PassportSuitableElement
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
"passportSuitableElement" -> Value -> Parser PassportSuitableElement
parsePassportSuitableElement Value
v
      String
_                         -> Parser PassportSuitableElement
forall a. Monoid a => a
mempty
    
    where
      parsePassportSuitableElement :: A.Value -> AT.Parser PassportSuitableElement
      parsePassportSuitableElement :: Value -> Parser PassportSuitableElement
parsePassportSuitableElement = String
-> (Object -> Parser PassportSuitableElement)
-> Value
-> Parser PassportSuitableElement
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PassportSuitableElement" ((Object -> Parser PassportSuitableElement)
 -> Value -> Parser PassportSuitableElement)
-> (Object -> Parser PassportSuitableElement)
-> Value
-> Parser PassportSuitableElement
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe PassportElementType
_type_                   <- Object
o Object -> Key -> Parser (Maybe PassportElementType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"type"
        Maybe Bool
is_selfie_required_      <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_selfie_required"
        Maybe Bool
is_translation_required_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_translation_required"
        Maybe Bool
is_native_name_required_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_native_name_required"
        PassportSuitableElement -> Parser PassportSuitableElement
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PassportSuitableElement -> Parser PassportSuitableElement)
-> PassportSuitableElement -> Parser PassportSuitableElement
forall a b. (a -> b) -> a -> b
$ PassportSuitableElement
          { _type :: Maybe PassportElementType
_type                   = Maybe PassportElementType
_type_
          , is_selfie_required :: Maybe Bool
is_selfie_required      = Maybe Bool
is_selfie_required_
          , is_translation_required :: Maybe Bool
is_translation_required = Maybe Bool
is_translation_required_
          , is_native_name_required :: Maybe Bool
is_native_name_required = Maybe Bool
is_native_name_required_
          }
  parseJSON Value
_ = Parser PassportSuitableElement
forall a. Monoid a => a
mempty