module TD.Query.ProcessChatJoinRequests
  (ProcessChatJoinRequests(..)
  , defaultProcessChatJoinRequests
  ) 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

-- | Handles all pending join requests for a given link in a chat. Returns 'TD.Data.Ok.Ok'
data ProcessChatJoinRequests
  = ProcessChatJoinRequests
    { ProcessChatJoinRequests -> Maybe Int
chat_id     :: Maybe Int    -- ^ Chat identifier
    , ProcessChatJoinRequests -> Maybe Text
invite_link :: Maybe T.Text -- ^ Invite link for which to process join requests. If empty, all join requests will be processed. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
    , ProcessChatJoinRequests -> Maybe Bool
approve     :: Maybe Bool   -- ^ Pass true to approve all requests; pass false to decline them
    }
  deriving (ProcessChatJoinRequests -> ProcessChatJoinRequests -> Bool
(ProcessChatJoinRequests -> ProcessChatJoinRequests -> Bool)
-> (ProcessChatJoinRequests -> ProcessChatJoinRequests -> Bool)
-> Eq ProcessChatJoinRequests
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProcessChatJoinRequests -> ProcessChatJoinRequests -> Bool
== :: ProcessChatJoinRequests -> ProcessChatJoinRequests -> Bool
$c/= :: ProcessChatJoinRequests -> ProcessChatJoinRequests -> Bool
/= :: ProcessChatJoinRequests -> ProcessChatJoinRequests -> Bool
Eq, Int -> ProcessChatJoinRequests -> ShowS
[ProcessChatJoinRequests] -> ShowS
ProcessChatJoinRequests -> String
(Int -> ProcessChatJoinRequests -> ShowS)
-> (ProcessChatJoinRequests -> String)
-> ([ProcessChatJoinRequests] -> ShowS)
-> Show ProcessChatJoinRequests
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProcessChatJoinRequests -> ShowS
showsPrec :: Int -> ProcessChatJoinRequests -> ShowS
$cshow :: ProcessChatJoinRequests -> String
show :: ProcessChatJoinRequests -> String
$cshowList :: [ProcessChatJoinRequests] -> ShowS
showList :: [ProcessChatJoinRequests] -> ShowS
Show)

instance I.ShortShow ProcessChatJoinRequests where
  shortShow :: ProcessChatJoinRequests -> String
shortShow
    ProcessChatJoinRequests
      { chat_id :: ProcessChatJoinRequests -> Maybe Int
chat_id     = Maybe Int
chat_id_
      , invite_link :: ProcessChatJoinRequests -> Maybe Text
invite_link = Maybe Text
invite_link_
      , approve :: ProcessChatJoinRequests -> Maybe Bool
approve     = Maybe Bool
approve_
      }
        = String
"ProcessChatJoinRequests"
          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
"invite_link" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
invite_link_
          , String
"approve"     String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
approve_
          ]

instance AT.ToJSON ProcessChatJoinRequests where
  toJSON :: ProcessChatJoinRequests -> Value
toJSON
    ProcessChatJoinRequests
      { chat_id :: ProcessChatJoinRequests -> Maybe Int
chat_id     = Maybe Int
chat_id_
      , invite_link :: ProcessChatJoinRequests -> Maybe Text
invite_link = Maybe Text
invite_link_
      , approve :: ProcessChatJoinRequests -> Maybe Bool
approve     = Maybe Bool
approve_
      }
        = [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
"processChatJoinRequests"
          , 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
"invite_link" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
invite_link_
          , Key
"approve"     Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
approve_
          ]

defaultProcessChatJoinRequests :: ProcessChatJoinRequests
defaultProcessChatJoinRequests :: ProcessChatJoinRequests
defaultProcessChatJoinRequests =
  ProcessChatJoinRequests
    { chat_id :: Maybe Int
chat_id     = Maybe Int
forall a. Maybe a
Nothing
    , invite_link :: Maybe Text
invite_link = Maybe Text
forall a. Maybe a
Nothing
    , approve :: Maybe Bool
approve     = Maybe Bool
forall a. Maybe a
Nothing
    }