module TD.Data.PassportElementErrorSource
  (PassportElementErrorSource(..)) 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

-- | Contains the description of an error in a Telegram Passport element
data PassportElementErrorSource
  = PassportElementErrorSourceUnspecified -- ^ The element contains an error in an unspecified place. The error will be considered resolved when new data is added
  | PassportElementErrorSourceDataField -- ^ One of the data fields contains an error. The error will be considered resolved when the value of the field changes
    { PassportElementErrorSource -> Maybe Text
field_name :: Maybe T.Text -- ^ Field name
    }
  | PassportElementErrorSourceFrontSide -- ^ The front side of the document contains an error. The error will be considered resolved when the file with the front side changes
  | PassportElementErrorSourceReverseSide -- ^ The reverse side of the document contains an error. The error will be considered resolved when the file with the reverse side changes
  | PassportElementErrorSourceSelfie -- ^ The selfie with the document contains an error. The error will be considered resolved when the file with the selfie changes
  | PassportElementErrorSourceTranslationFile -- ^ One of files with the translation of the document contains an error. The error will be considered resolved when the file changes
    { PassportElementErrorSource -> Maybe Int
file_index :: Maybe Int -- ^ Index of a file with the error
    }
  | PassportElementErrorSourceTranslationFiles -- ^ The translation of the document contains an error. The error will be considered resolved when the list of translation files changes
  | PassportElementErrorSourceFile -- ^ The file contains an error. The error will be considered resolved when the file changes
    { file_index :: Maybe Int -- ^ Index of a file with the error
    }
  | PassportElementErrorSourceFiles -- ^ The list of attached files contains an error. The error will be considered resolved when the list of files changes
  deriving (PassportElementErrorSource -> PassportElementErrorSource -> Bool
(PassportElementErrorSource -> PassportElementErrorSource -> Bool)
-> (PassportElementErrorSource
    -> PassportElementErrorSource -> Bool)
-> Eq PassportElementErrorSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PassportElementErrorSource -> PassportElementErrorSource -> Bool
== :: PassportElementErrorSource -> PassportElementErrorSource -> Bool
$c/= :: PassportElementErrorSource -> PassportElementErrorSource -> Bool
/= :: PassportElementErrorSource -> PassportElementErrorSource -> Bool
Eq, Int -> PassportElementErrorSource -> ShowS
[PassportElementErrorSource] -> ShowS
PassportElementErrorSource -> String
(Int -> PassportElementErrorSource -> ShowS)
-> (PassportElementErrorSource -> String)
-> ([PassportElementErrorSource] -> ShowS)
-> Show PassportElementErrorSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PassportElementErrorSource -> ShowS
showsPrec :: Int -> PassportElementErrorSource -> ShowS
$cshow :: PassportElementErrorSource -> String
show :: PassportElementErrorSource -> String
$cshowList :: [PassportElementErrorSource] -> ShowS
showList :: [PassportElementErrorSource] -> ShowS
Show)

instance I.ShortShow PassportElementErrorSource where
  shortShow :: PassportElementErrorSource -> String
shortShow PassportElementErrorSource
PassportElementErrorSourceUnspecified
      = String
"PassportElementErrorSourceUnspecified"
  shortShow PassportElementErrorSourceDataField
    { field_name :: PassportElementErrorSource -> Maybe Text
field_name = Maybe Text
field_name_
    }
      = String
"PassportElementErrorSourceDataField"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"field_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
field_name_
        ]
  shortShow PassportElementErrorSource
PassportElementErrorSourceFrontSide
      = String
"PassportElementErrorSourceFrontSide"
  shortShow PassportElementErrorSource
PassportElementErrorSourceReverseSide
      = String
"PassportElementErrorSourceReverseSide"
  shortShow PassportElementErrorSource
PassportElementErrorSourceSelfie
      = String
"PassportElementErrorSourceSelfie"
  shortShow PassportElementErrorSourceTranslationFile
    { file_index :: PassportElementErrorSource -> Maybe Int
file_index = Maybe Int
file_index_
    }
      = String
"PassportElementErrorSourceTranslationFile"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"file_index" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
file_index_
        ]
  shortShow PassportElementErrorSource
PassportElementErrorSourceTranslationFiles
      = String
"PassportElementErrorSourceTranslationFiles"
  shortShow PassportElementErrorSourceFile
    { file_index :: PassportElementErrorSource -> Maybe Int
file_index = Maybe Int
file_index_
    }
      = String
"PassportElementErrorSourceFile"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"file_index" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
file_index_
        ]
  shortShow PassportElementErrorSource
PassportElementErrorSourceFiles
      = String
"PassportElementErrorSourceFiles"

instance AT.FromJSON PassportElementErrorSource where
  parseJSON :: Value -> Parser PassportElementErrorSource
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
"passportElementErrorSourceUnspecified"      -> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PassportElementErrorSource
PassportElementErrorSourceUnspecified
      String
"passportElementErrorSourceDataField"        -> Value -> Parser PassportElementErrorSource
parsePassportElementErrorSourceDataField Value
v
      String
"passportElementErrorSourceFrontSide"        -> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PassportElementErrorSource
PassportElementErrorSourceFrontSide
      String
"passportElementErrorSourceReverseSide"      -> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PassportElementErrorSource
PassportElementErrorSourceReverseSide
      String
"passportElementErrorSourceSelfie"           -> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PassportElementErrorSource
PassportElementErrorSourceSelfie
      String
"passportElementErrorSourceTranslationFile"  -> Value -> Parser PassportElementErrorSource
parsePassportElementErrorSourceTranslationFile Value
v
      String
"passportElementErrorSourceTranslationFiles" -> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PassportElementErrorSource
PassportElementErrorSourceTranslationFiles
      String
"passportElementErrorSourceFile"             -> Value -> Parser PassportElementErrorSource
parsePassportElementErrorSourceFile Value
v
      String
"passportElementErrorSourceFiles"            -> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PassportElementErrorSource
PassportElementErrorSourceFiles
      String
_                                            -> Parser PassportElementErrorSource
forall a. Monoid a => a
mempty
    
    where
      parsePassportElementErrorSourceDataField :: A.Value -> AT.Parser PassportElementErrorSource
      parsePassportElementErrorSourceDataField :: Value -> Parser PassportElementErrorSource
parsePassportElementErrorSourceDataField = String
-> (Object -> Parser PassportElementErrorSource)
-> Value
-> Parser PassportElementErrorSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PassportElementErrorSourceDataField" ((Object -> Parser PassportElementErrorSource)
 -> Value -> Parser PassportElementErrorSource)
-> (Object -> Parser PassportElementErrorSource)
-> Value
-> Parser PassportElementErrorSource
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
field_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"field_name"
        PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PassportElementErrorSource -> Parser PassportElementErrorSource)
-> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a b. (a -> b) -> a -> b
$ PassportElementErrorSourceDataField
          { field_name :: Maybe Text
field_name = Maybe Text
field_name_
          }
      parsePassportElementErrorSourceTranslationFile :: A.Value -> AT.Parser PassportElementErrorSource
      parsePassportElementErrorSourceTranslationFile :: Value -> Parser PassportElementErrorSource
parsePassportElementErrorSourceTranslationFile = String
-> (Object -> Parser PassportElementErrorSource)
-> Value
-> Parser PassportElementErrorSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PassportElementErrorSourceTranslationFile" ((Object -> Parser PassportElementErrorSource)
 -> Value -> Parser PassportElementErrorSource)
-> (Object -> Parser PassportElementErrorSource)
-> Value
-> Parser PassportElementErrorSource
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
file_index_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"file_index"
        PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PassportElementErrorSource -> Parser PassportElementErrorSource)
-> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a b. (a -> b) -> a -> b
$ PassportElementErrorSourceTranslationFile
          { file_index :: Maybe Int
file_index = Maybe Int
file_index_
          }
      parsePassportElementErrorSourceFile :: A.Value -> AT.Parser PassportElementErrorSource
      parsePassportElementErrorSourceFile :: Value -> Parser PassportElementErrorSource
parsePassportElementErrorSourceFile = String
-> (Object -> Parser PassportElementErrorSource)
-> Value
-> Parser PassportElementErrorSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PassportElementErrorSourceFile" ((Object -> Parser PassportElementErrorSource)
 -> Value -> Parser PassportElementErrorSource)
-> (Object -> Parser PassportElementErrorSource)
-> Value
-> Parser PassportElementErrorSource
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
file_index_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"file_index"
        PassportElementErrorSource -> Parser PassportElementErrorSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PassportElementErrorSource -> Parser PassportElementErrorSource)
-> PassportElementErrorSource -> Parser PassportElementErrorSource
forall a b. (a -> b) -> a -> b
$ PassportElementErrorSourceFile
          { file_index :: Maybe Int
file_index = Maybe Int
file_index_
          }
  parseJSON Value
_ = Parser PassportElementErrorSource
forall a. Monoid a => a
mempty