module TD.Query.CreateChatInviteLink
  (CreateChatInviteLink(..)
  , defaultCreateChatInviteLink
  ) 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 new invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat. Returns 'TD.Data.ChatInviteLink.ChatInviteLink'
data CreateChatInviteLink
  = CreateChatInviteLink
    { CreateChatInviteLink -> Maybe Int
chat_id              :: Maybe Int    -- ^ Chat identifier
    , CreateChatInviteLink -> Maybe Text
name                 :: Maybe T.Text -- ^ Invite link name; 0-32 characters
    , CreateChatInviteLink -> Maybe Int
expiration_date      :: Maybe Int    -- ^ Point in time (Unix timestamp) when the link will expire; pass 0 if never
    , CreateChatInviteLink -> Maybe Int
member_limit         :: Maybe Int    -- ^ The maximum number of chat members that can join the chat via the link simultaneously; 0-99999; pass 0 if not limited
    , CreateChatInviteLink -> Maybe Bool
creates_join_request :: Maybe Bool   -- ^ Pass true if users joining the chat via the link need to be approved by chat administrators. In this case, member_limit must be 0
    }
  deriving (CreateChatInviteLink -> CreateChatInviteLink -> Bool
(CreateChatInviteLink -> CreateChatInviteLink -> Bool)
-> (CreateChatInviteLink -> CreateChatInviteLink -> Bool)
-> Eq CreateChatInviteLink
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CreateChatInviteLink -> CreateChatInviteLink -> Bool
== :: CreateChatInviteLink -> CreateChatInviteLink -> Bool
$c/= :: CreateChatInviteLink -> CreateChatInviteLink -> Bool
/= :: CreateChatInviteLink -> CreateChatInviteLink -> Bool
Eq, Int -> CreateChatInviteLink -> ShowS
[CreateChatInviteLink] -> ShowS
CreateChatInviteLink -> String
(Int -> CreateChatInviteLink -> ShowS)
-> (CreateChatInviteLink -> String)
-> ([CreateChatInviteLink] -> ShowS)
-> Show CreateChatInviteLink
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CreateChatInviteLink -> ShowS
showsPrec :: Int -> CreateChatInviteLink -> ShowS
$cshow :: CreateChatInviteLink -> String
show :: CreateChatInviteLink -> String
$cshowList :: [CreateChatInviteLink] -> ShowS
showList :: [CreateChatInviteLink] -> ShowS
Show)

instance I.ShortShow CreateChatInviteLink where
  shortShow :: CreateChatInviteLink -> String
shortShow
    CreateChatInviteLink
      { chat_id :: CreateChatInviteLink -> Maybe Int
chat_id              = Maybe Int
chat_id_
      , name :: CreateChatInviteLink -> Maybe Text
name                 = Maybe Text
name_
      , expiration_date :: CreateChatInviteLink -> Maybe Int
expiration_date      = Maybe Int
expiration_date_
      , member_limit :: CreateChatInviteLink -> Maybe Int
member_limit         = Maybe Int
member_limit_
      , creates_join_request :: CreateChatInviteLink -> Maybe Bool
creates_join_request = Maybe Bool
creates_join_request_
      }
        = String
"CreateChatInviteLink"
          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
"name"                 String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
          , String
"expiration_date"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expiration_date_
          , String
"member_limit"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
member_limit_
          , String
"creates_join_request" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
creates_join_request_
          ]

instance AT.ToJSON CreateChatInviteLink where
  toJSON :: CreateChatInviteLink -> Value
toJSON
    CreateChatInviteLink
      { chat_id :: CreateChatInviteLink -> Maybe Int
chat_id              = Maybe Int
chat_id_
      , name :: CreateChatInviteLink -> Maybe Text
name                 = Maybe Text
name_
      , expiration_date :: CreateChatInviteLink -> Maybe Int
expiration_date      = Maybe Int
expiration_date_
      , member_limit :: CreateChatInviteLink -> Maybe Int
member_limit         = Maybe Int
member_limit_
      , creates_join_request :: CreateChatInviteLink -> Maybe Bool
creates_join_request = Maybe Bool
creates_join_request_
      }
        = [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
"createChatInviteLink"
          , 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
"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
"expiration_date"      Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
expiration_date_
          , Key
"member_limit"         Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
member_limit_
          , Key
"creates_join_request" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
creates_join_request_
          ]

defaultCreateChatInviteLink :: CreateChatInviteLink
defaultCreateChatInviteLink :: CreateChatInviteLink
defaultCreateChatInviteLink =
  CreateChatInviteLink
    { chat_id :: Maybe Int
chat_id              = Maybe Int
forall a. Maybe a
Nothing
    , name :: Maybe Text
name                 = Maybe Text
forall a. Maybe a
Nothing
    , expiration_date :: Maybe Int
expiration_date      = Maybe Int
forall a. Maybe a
Nothing
    , member_limit :: Maybe Int
member_limit         = Maybe Int
forall a. Maybe a
Nothing
    , creates_join_request :: Maybe Bool
creates_join_request = Maybe Bool
forall a. Maybe a
Nothing
    }