module TD.Query.GetBotToken
  (GetBotToken(..)
  , defaultGetBotToken
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

-- | Returns token of a created bot; for bots only. Returns 'TD.Data.Text.Text'
data GetBotToken
  = GetBotToken
    { GetBotToken -> Maybe Int
bot_user_id :: Maybe Int  -- ^ Identifier of the created bot
    , GetBotToken -> Maybe Bool
revoke      :: Maybe Bool -- ^ Pass true to revoke the current token and create a new one
    }
  deriving (GetBotToken -> GetBotToken -> Bool
(GetBotToken -> GetBotToken -> Bool)
-> (GetBotToken -> GetBotToken -> Bool) -> Eq GetBotToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetBotToken -> GetBotToken -> Bool
== :: GetBotToken -> GetBotToken -> Bool
$c/= :: GetBotToken -> GetBotToken -> Bool
/= :: GetBotToken -> GetBotToken -> Bool
Eq, Int -> GetBotToken -> ShowS
[GetBotToken] -> ShowS
GetBotToken -> String
(Int -> GetBotToken -> ShowS)
-> (GetBotToken -> String)
-> ([GetBotToken] -> ShowS)
-> Show GetBotToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetBotToken -> ShowS
showsPrec :: Int -> GetBotToken -> ShowS
$cshow :: GetBotToken -> String
show :: GetBotToken -> String
$cshowList :: [GetBotToken] -> ShowS
showList :: [GetBotToken] -> ShowS
Show)

instance I.ShortShow GetBotToken where
  shortShow :: GetBotToken -> String
shortShow
    GetBotToken
      { bot_user_id :: GetBotToken -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
      , revoke :: GetBotToken -> Maybe Bool
revoke      = Maybe Bool
revoke_
      }
        = String
"GetBotToken"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
          , String
"revoke"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
revoke_
          ]

instance AT.ToJSON GetBotToken where
  toJSON :: GetBotToken -> Value
toJSON
    GetBotToken
      { bot_user_id :: GetBotToken -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
      , revoke :: GetBotToken -> Maybe Bool
revoke      = Maybe Bool
revoke_
      }
        = [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
"getBotToken"
          , Key
"bot_user_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
bot_user_id_
          , Key
"revoke"      Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
revoke_
          ]

defaultGetBotToken :: GetBotToken
defaultGetBotToken :: GetBotToken
defaultGetBotToken =
  GetBotToken
    { bot_user_id :: Maybe Int
bot_user_id = Maybe Int
forall a. Maybe a
Nothing
    , revoke :: Maybe Bool
revoke      = Maybe Bool
forall a. Maybe a
Nothing
    }