module TD.Query.JoinChat
  (JoinChat(..)
  ) where

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

-- | Adds the current user as a new member to a chat. Private and secret chats can't be joined using this method. May return an error with a message "INVITE_REQUEST_SENT" if only a join request was created. Returns 'TD.Data.Ok.Ok'
data JoinChat
  = JoinChat
    { JoinChat -> Maybe Int
chat_id :: Maybe Int -- ^ Chat identifier
    }
  deriving (JoinChat -> JoinChat -> Bool
(JoinChat -> JoinChat -> Bool)
-> (JoinChat -> JoinChat -> Bool) -> Eq JoinChat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JoinChat -> JoinChat -> Bool
== :: JoinChat -> JoinChat -> Bool
$c/= :: JoinChat -> JoinChat -> Bool
/= :: JoinChat -> JoinChat -> Bool
Eq, Int -> JoinChat -> ShowS
[JoinChat] -> ShowS
JoinChat -> String
(Int -> JoinChat -> ShowS)
-> (JoinChat -> String) -> ([JoinChat] -> ShowS) -> Show JoinChat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JoinChat -> ShowS
showsPrec :: Int -> JoinChat -> ShowS
$cshow :: JoinChat -> String
show :: JoinChat -> String
$cshowList :: [JoinChat] -> ShowS
showList :: [JoinChat] -> ShowS
Show)

instance I.ShortShow JoinChat where
  shortShow :: JoinChat -> String
shortShow
    JoinChat
      { chat_id :: JoinChat -> Maybe Int
chat_id = Maybe Int
chat_id_
      }
        = String
"JoinChat"
          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_
          ]

instance AT.ToJSON JoinChat where
  toJSON :: JoinChat -> Value
toJSON
    JoinChat
      { chat_id :: JoinChat -> Maybe Int
chat_id = Maybe Int
chat_id_
      }
        = [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
"joinChat"
          , 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_
          ]