module TD.Query.SetAuthenticationPhoneNumber
  (SetAuthenticationPhoneNumber(..)
  , defaultSetAuthenticationPhoneNumber
  ) 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
import qualified TD.Data.PhoneNumberAuthenticationSettings as PhoneNumberAuthenticationSettings

-- | Sets the phone number of the user and sends an authentication code to the user. Works only when the current authorization state is authorizationStateWaitPhoneNumber, or if there is no pending authentication query and the current authorization state is authorizationStateWaitEmailAddress, authorizationStateWaitEmailCode, authorizationStateWaitCode, authorizationStateWaitRegistration, or authorizationStateWaitPassword. Returns 'TD.Data.Ok.Ok'
data SetAuthenticationPhoneNumber
  = SetAuthenticationPhoneNumber
    { SetAuthenticationPhoneNumber -> Maybe Text
phone_number :: Maybe T.Text                                                              -- ^ The phone number of the user, in international format
    , SetAuthenticationPhoneNumber
-> Maybe PhoneNumberAuthenticationSettings
settings     :: Maybe PhoneNumberAuthenticationSettings.PhoneNumberAuthenticationSettings -- ^ Settings for the authentication of the user's phone number; pass null to use default settings
    }
  deriving (SetAuthenticationPhoneNumber
-> SetAuthenticationPhoneNumber -> Bool
(SetAuthenticationPhoneNumber
 -> SetAuthenticationPhoneNumber -> Bool)
-> (SetAuthenticationPhoneNumber
    -> SetAuthenticationPhoneNumber -> Bool)
-> Eq SetAuthenticationPhoneNumber
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetAuthenticationPhoneNumber
-> SetAuthenticationPhoneNumber -> Bool
== :: SetAuthenticationPhoneNumber
-> SetAuthenticationPhoneNumber -> Bool
$c/= :: SetAuthenticationPhoneNumber
-> SetAuthenticationPhoneNumber -> Bool
/= :: SetAuthenticationPhoneNumber
-> SetAuthenticationPhoneNumber -> Bool
Eq, Int -> SetAuthenticationPhoneNumber -> ShowS
[SetAuthenticationPhoneNumber] -> ShowS
SetAuthenticationPhoneNumber -> String
(Int -> SetAuthenticationPhoneNumber -> ShowS)
-> (SetAuthenticationPhoneNumber -> String)
-> ([SetAuthenticationPhoneNumber] -> ShowS)
-> Show SetAuthenticationPhoneNumber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetAuthenticationPhoneNumber -> ShowS
showsPrec :: Int -> SetAuthenticationPhoneNumber -> ShowS
$cshow :: SetAuthenticationPhoneNumber -> String
show :: SetAuthenticationPhoneNumber -> String
$cshowList :: [SetAuthenticationPhoneNumber] -> ShowS
showList :: [SetAuthenticationPhoneNumber] -> ShowS
Show)

instance I.ShortShow SetAuthenticationPhoneNumber where
  shortShow :: SetAuthenticationPhoneNumber -> String
shortShow
    SetAuthenticationPhoneNumber
      { phone_number :: SetAuthenticationPhoneNumber -> Maybe Text
phone_number = Maybe Text
phone_number_
      , settings :: SetAuthenticationPhoneNumber
-> Maybe PhoneNumberAuthenticationSettings
settings     = Maybe PhoneNumberAuthenticationSettings
settings_
      }
        = String
"SetAuthenticationPhoneNumber"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"phone_number" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
phone_number_
          , String
"settings"     String -> Maybe PhoneNumberAuthenticationSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe PhoneNumberAuthenticationSettings
settings_
          ]

instance AT.ToJSON SetAuthenticationPhoneNumber where
  toJSON :: SetAuthenticationPhoneNumber -> Value
toJSON
    SetAuthenticationPhoneNumber
      { phone_number :: SetAuthenticationPhoneNumber -> Maybe Text
phone_number = Maybe Text
phone_number_
      , settings :: SetAuthenticationPhoneNumber
-> Maybe PhoneNumberAuthenticationSettings
settings     = Maybe PhoneNumberAuthenticationSettings
settings_
      }
        = [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
"setAuthenticationPhoneNumber"
          , Key
"phone_number" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
phone_number_
          , Key
"settings"     Key -> Maybe PhoneNumberAuthenticationSettings -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe PhoneNumberAuthenticationSettings
settings_
          ]

defaultSetAuthenticationPhoneNumber :: SetAuthenticationPhoneNumber
defaultSetAuthenticationPhoneNumber :: SetAuthenticationPhoneNumber
defaultSetAuthenticationPhoneNumber =
  SetAuthenticationPhoneNumber
    { phone_number :: Maybe Text
phone_number = Maybe Text
forall a. Maybe a
Nothing
    , settings :: Maybe PhoneNumberAuthenticationSettings
settings     = Maybe PhoneNumberAuthenticationSettings
forall a. Maybe a
Nothing
    }