module TD.Query.CreateBot
  (CreateBot(..)
  , defaultCreateBot
  ) 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

-- | Creates a bot which will be managed by another bot. Returns the created bot. May return an error with a message "BOT_CREATE_LIMIT_EXCEEDED" if the user already owns the maximum allowed number of bots as per getOption("owned_bot_count_max"). An internal link "https://t.me/BotFather?start=deletebot" can be processed to handle the error. Returns 'TD.Data.User.User'
data CreateBot
  = CreateBot
    { CreateBot -> Maybe Int
manager_bot_user_id :: Maybe Int    -- ^ Identifier of the bot that will manage the created bot
    , CreateBot -> Maybe Text
name                :: Maybe T.Text -- ^ Name of the bot; 1-64 characters
    , CreateBot -> Maybe Text
username            :: Maybe T.Text -- ^ Username of the bot. The username must end with "bot" or a string from updateAllowedBotUsernamePremiumSuffixes case-insensitive. Use checkBotUsername to find whether the name is suitable. If the username doesn't end with "bot", then the current user must have Telegram Premium subscription, the chosen username will be assigned as secondary and an additional regular username ending with "bot" will be automatically assigned to the created bot
    , CreateBot -> Maybe Bool
via_link            :: Maybe Bool   -- ^ Pass true if the bot is created from an internalLinkTypeRequestManagedBot link
    }
  deriving (CreateBot -> CreateBot -> Bool
(CreateBot -> CreateBot -> Bool)
-> (CreateBot -> CreateBot -> Bool) -> Eq CreateBot
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CreateBot -> CreateBot -> Bool
== :: CreateBot -> CreateBot -> Bool
$c/= :: CreateBot -> CreateBot -> Bool
/= :: CreateBot -> CreateBot -> Bool
Eq, Int -> CreateBot -> ShowS
[CreateBot] -> ShowS
CreateBot -> String
(Int -> CreateBot -> ShowS)
-> (CreateBot -> String)
-> ([CreateBot] -> ShowS)
-> Show CreateBot
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CreateBot -> ShowS
showsPrec :: Int -> CreateBot -> ShowS
$cshow :: CreateBot -> String
show :: CreateBot -> String
$cshowList :: [CreateBot] -> ShowS
showList :: [CreateBot] -> ShowS
Show)

instance I.ShortShow CreateBot where
  shortShow :: CreateBot -> String
shortShow
    CreateBot
      { manager_bot_user_id :: CreateBot -> Maybe Int
manager_bot_user_id = Maybe Int
manager_bot_user_id_
      , name :: CreateBot -> Maybe Text
name                = Maybe Text
name_
      , username :: CreateBot -> Maybe Text
username            = Maybe Text
username_
      , via_link :: CreateBot -> Maybe Bool
via_link            = Maybe Bool
via_link_
      }
        = String
"CreateBot"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"manager_bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
manager_bot_user_id_
          , String
"name"                String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
          , String
"username"            String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
username_
          , String
"via_link"            String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
via_link_
          ]

instance AT.ToJSON CreateBot where
  toJSON :: CreateBot -> Value
toJSON
    CreateBot
      { manager_bot_user_id :: CreateBot -> Maybe Int
manager_bot_user_id = Maybe Int
manager_bot_user_id_
      , name :: CreateBot -> Maybe Text
name                = Maybe Text
name_
      , username :: CreateBot -> Maybe Text
username            = Maybe Text
username_
      , via_link :: CreateBot -> Maybe Bool
via_link            = Maybe Bool
via_link_
      }
        = [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
"createBot"
          , Key
"manager_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
manager_bot_user_id_
          , Key
"name"                Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
name_
          , 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_
          , Key
"via_link"            Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
via_link_
          ]

defaultCreateBot :: CreateBot
defaultCreateBot :: CreateBot
defaultCreateBot =
  CreateBot
    { manager_bot_user_id :: Maybe Int
manager_bot_user_id = Maybe Int
forall a. Maybe a
Nothing
    , name :: Maybe Text
name                = Maybe Text
forall a. Maybe a
Nothing
    , username :: Maybe Text
username            = Maybe Text
forall a. Maybe a
Nothing
    , via_link :: Maybe Bool
via_link            = Maybe Bool
forall a. Maybe a
Nothing
    }