module TD.Query.ProcessChatJoinRequest
  (ProcessChatJoinRequest(..)
  , defaultProcessChatJoinRequest
  ) where

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

-- | Handles a pending join request in a chat. Returns 'TD.Data.Ok.Ok'
data ProcessChatJoinRequest
  = ProcessChatJoinRequest
    { ProcessChatJoinRequest -> Maybe Int
chat_id :: Maybe Int  -- ^ Chat identifier
    , ProcessChatJoinRequest -> Maybe Int
user_id :: Maybe Int  -- ^ Identifier of the user that sent the request
    , ProcessChatJoinRequest -> Maybe Bool
approve :: Maybe Bool -- ^ Pass true to approve the request; pass false to decline it
    }
  deriving (ProcessChatJoinRequest -> ProcessChatJoinRequest -> Bool
(ProcessChatJoinRequest -> ProcessChatJoinRequest -> Bool)
-> (ProcessChatJoinRequest -> ProcessChatJoinRequest -> Bool)
-> Eq ProcessChatJoinRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProcessChatJoinRequest -> ProcessChatJoinRequest -> Bool
== :: ProcessChatJoinRequest -> ProcessChatJoinRequest -> Bool
$c/= :: ProcessChatJoinRequest -> ProcessChatJoinRequest -> Bool
/= :: ProcessChatJoinRequest -> ProcessChatJoinRequest -> Bool
Eq, Int -> ProcessChatJoinRequest -> ShowS
[ProcessChatJoinRequest] -> ShowS
ProcessChatJoinRequest -> String
(Int -> ProcessChatJoinRequest -> ShowS)
-> (ProcessChatJoinRequest -> String)
-> ([ProcessChatJoinRequest] -> ShowS)
-> Show ProcessChatJoinRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProcessChatJoinRequest -> ShowS
showsPrec :: Int -> ProcessChatJoinRequest -> ShowS
$cshow :: ProcessChatJoinRequest -> String
show :: ProcessChatJoinRequest -> String
$cshowList :: [ProcessChatJoinRequest] -> ShowS
showList :: [ProcessChatJoinRequest] -> ShowS
Show)

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

instance AT.ToJSON ProcessChatJoinRequest where
  toJSON :: ProcessChatJoinRequest -> Value
toJSON
    ProcessChatJoinRequest
      { chat_id :: ProcessChatJoinRequest -> Maybe Int
chat_id = Maybe Int
chat_id_
      , user_id :: ProcessChatJoinRequest -> Maybe Int
user_id = Maybe Int
user_id_
      , approve :: ProcessChatJoinRequest -> 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
"processChatJoinRequest"
          , 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
"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
user_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_
          ]

defaultProcessChatJoinRequest :: ProcessChatJoinRequest
defaultProcessChatJoinRequest :: ProcessChatJoinRequest
defaultProcessChatJoinRequest =
  ProcessChatJoinRequest
    { chat_id :: Maybe Int
chat_id = Maybe Int
forall a. Maybe a
Nothing
    , user_id :: Maybe Int
user_id = Maybe Int
forall a. Maybe a
Nothing
    , approve :: Maybe Bool
approve = Maybe Bool
forall a. Maybe a
Nothing
    }