module TD.Data.InputPassportElementError
  ( InputPassportElementError(..)    
  , defaultInputPassportElementError 
  ) 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
import qualified Data.Text as T
import qualified TD.Data.InputPassportElementErrorSource as InputPassportElementErrorSource

data InputPassportElementError
  = InputPassportElementError -- ^ Contains the description of an error in a Telegram Passport element; for bots only
    { InputPassportElementError -> Maybe PassportElementType
_type   :: Maybe PassportElementType.PassportElementType                         -- ^ Type of Telegram Passport element that has the error
    , InputPassportElementError -> Maybe Text
message :: Maybe T.Text                                                          -- ^ Error message
    , InputPassportElementError -> Maybe InputPassportElementErrorSource
source  :: Maybe InputPassportElementErrorSource.InputPassportElementErrorSource -- ^ Error source
    }
  deriving (InputPassportElementError -> InputPassportElementError -> Bool
(InputPassportElementError -> InputPassportElementError -> Bool)
-> (InputPassportElementError -> InputPassportElementError -> Bool)
-> Eq InputPassportElementError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputPassportElementError -> InputPassportElementError -> Bool
== :: InputPassportElementError -> InputPassportElementError -> Bool
$c/= :: InputPassportElementError -> InputPassportElementError -> Bool
/= :: InputPassportElementError -> InputPassportElementError -> Bool
Eq, Int -> InputPassportElementError -> ShowS
[InputPassportElementError] -> ShowS
InputPassportElementError -> String
(Int -> InputPassportElementError -> ShowS)
-> (InputPassportElementError -> String)
-> ([InputPassportElementError] -> ShowS)
-> Show InputPassportElementError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputPassportElementError -> ShowS
showsPrec :: Int -> InputPassportElementError -> ShowS
$cshow :: InputPassportElementError -> String
show :: InputPassportElementError -> String
$cshowList :: [InputPassportElementError] -> ShowS
showList :: [InputPassportElementError] -> ShowS
Show)

instance I.ShortShow InputPassportElementError where
  shortShow :: InputPassportElementError -> String
shortShow InputPassportElementError
    { _type :: InputPassportElementError -> Maybe PassportElementType
_type   = Maybe PassportElementType
_type_
    , message :: InputPassportElementError -> Maybe Text
message = Maybe Text
message_
    , source :: InputPassportElementError -> Maybe InputPassportElementErrorSource
source  = Maybe InputPassportElementErrorSource
source_
    }
      = String
"InputPassportElementError"
        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
"message" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
message_
        , String
"source"  String -> Maybe InputPassportElementErrorSource -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputPassportElementErrorSource
source_
        ]

instance AT.FromJSON InputPassportElementError where
  parseJSON :: Value -> Parser InputPassportElementError
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
"inputPassportElementError" -> Value -> Parser InputPassportElementError
parseInputPassportElementError Value
v
      String
_                           -> Parser InputPassportElementError
forall a. Monoid a => a
mempty
    
    where
      parseInputPassportElementError :: A.Value -> AT.Parser InputPassportElementError
      parseInputPassportElementError :: Value -> Parser InputPassportElementError
parseInputPassportElementError = String
-> (Object -> Parser InputPassportElementError)
-> Value
-> Parser InputPassportElementError
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputPassportElementError" ((Object -> Parser InputPassportElementError)
 -> Value -> Parser InputPassportElementError)
-> (Object -> Parser InputPassportElementError)
-> Value
-> Parser InputPassportElementError
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 Text
message_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message"
        Maybe InputPassportElementErrorSource
source_  <- Object
o Object -> Key -> Parser (Maybe InputPassportElementErrorSource)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"source"
        InputPassportElementError -> Parser InputPassportElementError
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputPassportElementError -> Parser InputPassportElementError)
-> InputPassportElementError -> Parser InputPassportElementError
forall a b. (a -> b) -> a -> b
$ InputPassportElementError
          { _type :: Maybe PassportElementType
_type   = Maybe PassportElementType
_type_
          , message :: Maybe Text
message = Maybe Text
message_
          , source :: Maybe InputPassportElementErrorSource
source  = Maybe InputPassportElementErrorSource
source_
          }
  parseJSON Value
_ = Parser InputPassportElementError
forall a. Monoid a => a
mempty

instance AT.ToJSON InputPassportElementError where
  toJSON :: InputPassportElementError -> Value
toJSON InputPassportElementError
    { _type :: InputPassportElementError -> Maybe PassportElementType
_type   = Maybe PassportElementType
_type_
    , message :: InputPassportElementError -> Maybe Text
message = Maybe Text
message_
    , source :: InputPassportElementError -> Maybe InputPassportElementErrorSource
source  = Maybe InputPassportElementErrorSource
source_
    }
      = [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
"inputPassportElementError"
        , Key
"type"    Key -> Maybe PassportElementType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe PassportElementType
_type_
        , Key
"message" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
message_
        , Key
"source"  Key -> Maybe InputPassportElementErrorSource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputPassportElementErrorSource
source_
        ]

defaultInputPassportElementError :: InputPassportElementError
defaultInputPassportElementError :: InputPassportElementError
defaultInputPassportElementError =
  InputPassportElementError
    { _type :: Maybe PassportElementType
_type   = Maybe PassportElementType
forall a. Maybe a
Nothing
    , message :: Maybe Text
message = Maybe Text
forall a. Maybe a
Nothing
    , source :: Maybe InputPassportElementErrorSource
source  = Maybe InputPassportElementErrorSource
forall a. Maybe a
Nothing
    }