module TD.Data.PhoneNumberAuthenticationSettings
  ( PhoneNumberAuthenticationSettings(..)    
  , defaultPhoneNumberAuthenticationSettings 
  ) 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.FirebaseAuthenticationSettings as FirebaseAuthenticationSettings
import qualified Data.Text as T

data PhoneNumberAuthenticationSettings
  = PhoneNumberAuthenticationSettings -- ^ Contains settings for the authentication of the user's phone number
    { PhoneNumberAuthenticationSettings -> Maybe Bool
allow_flash_call                 :: Maybe Bool                                                          -- ^ Pass true if the authentication code may be sent via a flash call to the specified phone number
    , PhoneNumberAuthenticationSettings -> Maybe Bool
allow_missed_call                :: Maybe Bool                                                          -- ^ Pass true if the authentication code may be sent via a missed call to the specified phone number
    , PhoneNumberAuthenticationSettings -> Maybe Bool
is_current_phone_number          :: Maybe Bool                                                          -- ^ Pass true if the authenticated phone number is used on the current device
    , PhoneNumberAuthenticationSettings -> Maybe Bool
has_unknown_phone_number         :: Maybe Bool                                                          -- ^ Pass true if there is a SIM card in the current device, but it is not possible to check whether phone number matches
    , PhoneNumberAuthenticationSettings -> Maybe Bool
allow_sms_retriever_api          :: Maybe Bool                                                          -- ^ For official applications only. True, if the application can use Android SMS Retriever API (requires Google Play Services >= 10.2) to automatically receive the authentication code from the SMS. See https://developers.google.com/identity/sms-retriever/ for more details
    , PhoneNumberAuthenticationSettings
-> Maybe FirebaseAuthenticationSettings
firebase_authentication_settings :: Maybe FirebaseAuthenticationSettings.FirebaseAuthenticationSettings -- ^ For official Android and iOS applications only; pass null otherwise. Settings for Firebase Authentication
    , PhoneNumberAuthenticationSettings -> Maybe [Text]
authentication_tokens            :: Maybe [T.Text]                                                      -- ^ List of up to 20 authentication tokens, recently received in updateOption("authentication_token") in previously logged out sessions
    }
  deriving (PhoneNumberAuthenticationSettings
-> PhoneNumberAuthenticationSettings -> Bool
(PhoneNumberAuthenticationSettings
 -> PhoneNumberAuthenticationSettings -> Bool)
-> (PhoneNumberAuthenticationSettings
    -> PhoneNumberAuthenticationSettings -> Bool)
-> Eq PhoneNumberAuthenticationSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PhoneNumberAuthenticationSettings
-> PhoneNumberAuthenticationSettings -> Bool
== :: PhoneNumberAuthenticationSettings
-> PhoneNumberAuthenticationSettings -> Bool
$c/= :: PhoneNumberAuthenticationSettings
-> PhoneNumberAuthenticationSettings -> Bool
/= :: PhoneNumberAuthenticationSettings
-> PhoneNumberAuthenticationSettings -> Bool
Eq, Int -> PhoneNumberAuthenticationSettings -> ShowS
[PhoneNumberAuthenticationSettings] -> ShowS
PhoneNumberAuthenticationSettings -> String
(Int -> PhoneNumberAuthenticationSettings -> ShowS)
-> (PhoneNumberAuthenticationSettings -> String)
-> ([PhoneNumberAuthenticationSettings] -> ShowS)
-> Show PhoneNumberAuthenticationSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PhoneNumberAuthenticationSettings -> ShowS
showsPrec :: Int -> PhoneNumberAuthenticationSettings -> ShowS
$cshow :: PhoneNumberAuthenticationSettings -> String
show :: PhoneNumberAuthenticationSettings -> String
$cshowList :: [PhoneNumberAuthenticationSettings] -> ShowS
showList :: [PhoneNumberAuthenticationSettings] -> ShowS
Show)

instance I.ShortShow PhoneNumberAuthenticationSettings where
  shortShow :: PhoneNumberAuthenticationSettings -> String
shortShow PhoneNumberAuthenticationSettings
    { allow_flash_call :: PhoneNumberAuthenticationSettings -> Maybe Bool
allow_flash_call                 = Maybe Bool
allow_flash_call_
    , allow_missed_call :: PhoneNumberAuthenticationSettings -> Maybe Bool
allow_missed_call                = Maybe Bool
allow_missed_call_
    , is_current_phone_number :: PhoneNumberAuthenticationSettings -> Maybe Bool
is_current_phone_number          = Maybe Bool
is_current_phone_number_
    , has_unknown_phone_number :: PhoneNumberAuthenticationSettings -> Maybe Bool
has_unknown_phone_number         = Maybe Bool
has_unknown_phone_number_
    , allow_sms_retriever_api :: PhoneNumberAuthenticationSettings -> Maybe Bool
allow_sms_retriever_api          = Maybe Bool
allow_sms_retriever_api_
    , firebase_authentication_settings :: PhoneNumberAuthenticationSettings
-> Maybe FirebaseAuthenticationSettings
firebase_authentication_settings = Maybe FirebaseAuthenticationSettings
firebase_authentication_settings_
    , authentication_tokens :: PhoneNumberAuthenticationSettings -> Maybe [Text]
authentication_tokens            = Maybe [Text]
authentication_tokens_
    }
      = String
"PhoneNumberAuthenticationSettings"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"allow_flash_call"                 String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_flash_call_
        , String
"allow_missed_call"                String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_missed_call_
        , String
"is_current_phone_number"          String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_current_phone_number_
        , String
"has_unknown_phone_number"         String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_unknown_phone_number_
        , String
"allow_sms_retriever_api"          String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_sms_retriever_api_
        , String
"firebase_authentication_settings" String -> Maybe FirebaseAuthenticationSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FirebaseAuthenticationSettings
firebase_authentication_settings_
        , String
"authentication_tokens"            String -> Maybe [Text] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Text]
authentication_tokens_
        ]

instance AT.FromJSON PhoneNumberAuthenticationSettings where
  parseJSON :: Value -> Parser PhoneNumberAuthenticationSettings
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
"phoneNumberAuthenticationSettings" -> Value -> Parser PhoneNumberAuthenticationSettings
parsePhoneNumberAuthenticationSettings Value
v
      String
_                                   -> Parser PhoneNumberAuthenticationSettings
forall a. Monoid a => a
mempty
    
    where
      parsePhoneNumberAuthenticationSettings :: A.Value -> AT.Parser PhoneNumberAuthenticationSettings
      parsePhoneNumberAuthenticationSettings :: Value -> Parser PhoneNumberAuthenticationSettings
parsePhoneNumberAuthenticationSettings = String
-> (Object -> Parser PhoneNumberAuthenticationSettings)
-> Value
-> Parser PhoneNumberAuthenticationSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PhoneNumberAuthenticationSettings" ((Object -> Parser PhoneNumberAuthenticationSettings)
 -> Value -> Parser PhoneNumberAuthenticationSettings)
-> (Object -> Parser PhoneNumberAuthenticationSettings)
-> Value
-> Parser PhoneNumberAuthenticationSettings
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
allow_flash_call_                 <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"allow_flash_call"
        Maybe Bool
allow_missed_call_                <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"allow_missed_call"
        Maybe Bool
is_current_phone_number_          <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_current_phone_number"
        Maybe Bool
has_unknown_phone_number_         <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"has_unknown_phone_number"
        Maybe Bool
allow_sms_retriever_api_          <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"allow_sms_retriever_api"
        Maybe FirebaseAuthenticationSettings
firebase_authentication_settings_ <- Object
o Object -> Key -> Parser (Maybe FirebaseAuthenticationSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"firebase_authentication_settings"
        Maybe [Text]
authentication_tokens_            <- Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"authentication_tokens"
        PhoneNumberAuthenticationSettings
-> Parser PhoneNumberAuthenticationSettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PhoneNumberAuthenticationSettings
 -> Parser PhoneNumberAuthenticationSettings)
-> PhoneNumberAuthenticationSettings
-> Parser PhoneNumberAuthenticationSettings
forall a b. (a -> b) -> a -> b
$ PhoneNumberAuthenticationSettings
          { allow_flash_call :: Maybe Bool
allow_flash_call                 = Maybe Bool
allow_flash_call_
          , allow_missed_call :: Maybe Bool
allow_missed_call                = Maybe Bool
allow_missed_call_
          , is_current_phone_number :: Maybe Bool
is_current_phone_number          = Maybe Bool
is_current_phone_number_
          , has_unknown_phone_number :: Maybe Bool
has_unknown_phone_number         = Maybe Bool
has_unknown_phone_number_
          , allow_sms_retriever_api :: Maybe Bool
allow_sms_retriever_api          = Maybe Bool
allow_sms_retriever_api_
          , firebase_authentication_settings :: Maybe FirebaseAuthenticationSettings
firebase_authentication_settings = Maybe FirebaseAuthenticationSettings
firebase_authentication_settings_
          , authentication_tokens :: Maybe [Text]
authentication_tokens            = Maybe [Text]
authentication_tokens_
          }
  parseJSON Value
_ = Parser PhoneNumberAuthenticationSettings
forall a. Monoid a => a
mempty

instance AT.ToJSON PhoneNumberAuthenticationSettings where
  toJSON :: PhoneNumberAuthenticationSettings -> Value
toJSON PhoneNumberAuthenticationSettings
    { allow_flash_call :: PhoneNumberAuthenticationSettings -> Maybe Bool
allow_flash_call                 = Maybe Bool
allow_flash_call_
    , allow_missed_call :: PhoneNumberAuthenticationSettings -> Maybe Bool
allow_missed_call                = Maybe Bool
allow_missed_call_
    , is_current_phone_number :: PhoneNumberAuthenticationSettings -> Maybe Bool
is_current_phone_number          = Maybe Bool
is_current_phone_number_
    , has_unknown_phone_number :: PhoneNumberAuthenticationSettings -> Maybe Bool
has_unknown_phone_number         = Maybe Bool
has_unknown_phone_number_
    , allow_sms_retriever_api :: PhoneNumberAuthenticationSettings -> Maybe Bool
allow_sms_retriever_api          = Maybe Bool
allow_sms_retriever_api_
    , firebase_authentication_settings :: PhoneNumberAuthenticationSettings
-> Maybe FirebaseAuthenticationSettings
firebase_authentication_settings = Maybe FirebaseAuthenticationSettings
firebase_authentication_settings_
    , authentication_tokens :: PhoneNumberAuthenticationSettings -> Maybe [Text]
authentication_tokens            = Maybe [Text]
authentication_tokens_
    }
      = [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
"phoneNumberAuthenticationSettings"
        , Key
"allow_flash_call"                 Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_flash_call_
        , Key
"allow_missed_call"                Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_missed_call_
        , Key
"is_current_phone_number"          Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_current_phone_number_
        , Key
"has_unknown_phone_number"         Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
has_unknown_phone_number_
        , Key
"allow_sms_retriever_api"          Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_sms_retriever_api_
        , Key
"firebase_authentication_settings" Key -> Maybe FirebaseAuthenticationSettings -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FirebaseAuthenticationSettings
firebase_authentication_settings_
        , Key
"authentication_tokens"            Key -> Maybe [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Text]
authentication_tokens_
        ]

defaultPhoneNumberAuthenticationSettings :: PhoneNumberAuthenticationSettings
defaultPhoneNumberAuthenticationSettings :: PhoneNumberAuthenticationSettings
defaultPhoneNumberAuthenticationSettings =
  PhoneNumberAuthenticationSettings
    { allow_flash_call :: Maybe Bool
allow_flash_call                 = Maybe Bool
forall a. Maybe a
Nothing
    , allow_missed_call :: Maybe Bool
allow_missed_call                = Maybe Bool
forall a. Maybe a
Nothing
    , is_current_phone_number :: Maybe Bool
is_current_phone_number          = Maybe Bool
forall a. Maybe a
Nothing
    , has_unknown_phone_number :: Maybe Bool
has_unknown_phone_number         = Maybe Bool
forall a. Maybe a
Nothing
    , allow_sms_retriever_api :: Maybe Bool
allow_sms_retriever_api          = Maybe Bool
forall a. Maybe a
Nothing
    , firebase_authentication_settings :: Maybe FirebaseAuthenticationSettings
firebase_authentication_settings = Maybe FirebaseAuthenticationSettings
forall a. Maybe a
Nothing
    , authentication_tokens :: Maybe [Text]
authentication_tokens            = Maybe [Text]
forall a. Maybe a
Nothing
    }