module TD.Query.CheckChatUsername
  (CheckChatUsername(..)
  , defaultCheckChatUsername
  ) 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

-- | Checks whether a username can be set for a chat. Returns 'TD.Data.CheckChatUsernameResult.CheckChatUsernameResult'
data CheckChatUsername
  = CheckChatUsername
    { CheckChatUsername -> Maybe Int
chat_id  :: Maybe Int    -- ^ Chat identifier; must be identifier of a supergroup chat, or a channel chat, or a private chat with self, or 0 if the chat is being created
    , CheckChatUsername -> Maybe Text
username :: Maybe T.Text -- ^ Username to be checked
    }
  deriving (CheckChatUsername -> CheckChatUsername -> Bool
(CheckChatUsername -> CheckChatUsername -> Bool)
-> (CheckChatUsername -> CheckChatUsername -> Bool)
-> Eq CheckChatUsername
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CheckChatUsername -> CheckChatUsername -> Bool
== :: CheckChatUsername -> CheckChatUsername -> Bool
$c/= :: CheckChatUsername -> CheckChatUsername -> Bool
/= :: CheckChatUsername -> CheckChatUsername -> Bool
Eq, Int -> CheckChatUsername -> ShowS
[CheckChatUsername] -> ShowS
CheckChatUsername -> String
(Int -> CheckChatUsername -> ShowS)
-> (CheckChatUsername -> String)
-> ([CheckChatUsername] -> ShowS)
-> Show CheckChatUsername
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CheckChatUsername -> ShowS
showsPrec :: Int -> CheckChatUsername -> ShowS
$cshow :: CheckChatUsername -> String
show :: CheckChatUsername -> String
$cshowList :: [CheckChatUsername] -> ShowS
showList :: [CheckChatUsername] -> ShowS
Show)

instance I.ShortShow CheckChatUsername where
  shortShow :: CheckChatUsername -> String
shortShow
    CheckChatUsername
      { chat_id :: CheckChatUsername -> Maybe Int
chat_id  = Maybe Int
chat_id_
      , username :: CheckChatUsername -> Maybe Text
username = Maybe Text
username_
      }
        = String
"CheckChatUsername"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"chat_id"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"username" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
username_
          ]

instance AT.ToJSON CheckChatUsername where
  toJSON :: CheckChatUsername -> Value
toJSON
    CheckChatUsername
      { chat_id :: CheckChatUsername -> Maybe Int
chat_id  = Maybe Int
chat_id_
      , username :: CheckChatUsername -> Maybe Text
username = Maybe Text
username_
      }
        = [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
"checkChatUsername"
          , Key
"chat_id"  Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
chat_id_
          , Key
"username" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
username_
          ]

defaultCheckChatUsername :: CheckChatUsername
defaultCheckChatUsername :: CheckChatUsername
defaultCheckChatUsername =
  CheckChatUsername
    { chat_id :: Maybe Int
chat_id  = Maybe Int
forall a. Maybe a
Nothing
    , username :: Maybe Text
username = Maybe Text
forall a. Maybe a
Nothing
    }