module TD.Query.ProcessCommunityAddChatRequest
  (ProcessCommunityAddChatRequest(..)
  , defaultProcessCommunityAddChatRequest
  ) where

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

-- | Handles a pending request to add a chat to a community; requires can_edit_chat_list administrator right in the community. Returns 'TD.Data.Ok.Ok'
data ProcessCommunityAddChatRequest
  = ProcessCommunityAddChatRequest
    { ProcessCommunityAddChatRequest -> Maybe Int
community_id :: Maybe Int  -- ^ Identifier of the community
    , ProcessCommunityAddChatRequest -> Maybe Int
chat_id      :: Maybe Int  -- ^ Identifier of the chat from the request
    , ProcessCommunityAddChatRequest -> Maybe Bool
approve      :: Maybe Bool -- ^ Pass true to approve the request and add the chat to the community; pass false to decline it. If the community already has the maximum number of chats, then approval fails with the error "COMMUNITY_PEERS_TOO_MUCH"
    }
  deriving (ProcessCommunityAddChatRequest
-> ProcessCommunityAddChatRequest -> Bool
(ProcessCommunityAddChatRequest
 -> ProcessCommunityAddChatRequest -> Bool)
-> (ProcessCommunityAddChatRequest
    -> ProcessCommunityAddChatRequest -> Bool)
-> Eq ProcessCommunityAddChatRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProcessCommunityAddChatRequest
-> ProcessCommunityAddChatRequest -> Bool
== :: ProcessCommunityAddChatRequest
-> ProcessCommunityAddChatRequest -> Bool
$c/= :: ProcessCommunityAddChatRequest
-> ProcessCommunityAddChatRequest -> Bool
/= :: ProcessCommunityAddChatRequest
-> ProcessCommunityAddChatRequest -> Bool
Eq, Int -> ProcessCommunityAddChatRequest -> ShowS
[ProcessCommunityAddChatRequest] -> ShowS
ProcessCommunityAddChatRequest -> String
(Int -> ProcessCommunityAddChatRequest -> ShowS)
-> (ProcessCommunityAddChatRequest -> String)
-> ([ProcessCommunityAddChatRequest] -> ShowS)
-> Show ProcessCommunityAddChatRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProcessCommunityAddChatRequest -> ShowS
showsPrec :: Int -> ProcessCommunityAddChatRequest -> ShowS
$cshow :: ProcessCommunityAddChatRequest -> String
show :: ProcessCommunityAddChatRequest -> String
$cshowList :: [ProcessCommunityAddChatRequest] -> ShowS
showList :: [ProcessCommunityAddChatRequest] -> ShowS
Show)

instance I.ShortShow ProcessCommunityAddChatRequest where
  shortShow :: ProcessCommunityAddChatRequest -> String
shortShow
    ProcessCommunityAddChatRequest
      { community_id :: ProcessCommunityAddChatRequest -> Maybe Int
community_id = Maybe Int
community_id_
      , chat_id :: ProcessCommunityAddChatRequest -> Maybe Int
chat_id      = Maybe Int
chat_id_
      , approve :: ProcessCommunityAddChatRequest -> Maybe Bool
approve      = Maybe Bool
approve_
      }
        = String
"ProcessCommunityAddChatRequest"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"community_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
community_id_
          , String
"chat_id"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"approve"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
approve_
          ]

instance AT.ToJSON ProcessCommunityAddChatRequest where
  toJSON :: ProcessCommunityAddChatRequest -> Value
toJSON
    ProcessCommunityAddChatRequest
      { community_id :: ProcessCommunityAddChatRequest -> Maybe Int
community_id = Maybe Int
community_id_
      , chat_id :: ProcessCommunityAddChatRequest -> Maybe Int
chat_id      = Maybe Int
chat_id_
      , approve :: ProcessCommunityAddChatRequest -> 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
"processCommunityAddChatRequest"
          , Key
"community_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
community_id_
          , 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
"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_
          ]

defaultProcessCommunityAddChatRequest :: ProcessCommunityAddChatRequest
defaultProcessCommunityAddChatRequest :: ProcessCommunityAddChatRequest
defaultProcessCommunityAddChatRequest =
  ProcessCommunityAddChatRequest
    { community_id :: Maybe Int
community_id = Maybe Int
forall a. Maybe a
Nothing
    , chat_id :: Maybe Int
chat_id      = Maybe Int
forall a. Maybe a
Nothing
    , approve :: Maybe Bool
approve      = Maybe Bool
forall a. Maybe a
Nothing
    }