module TD.Query.AddCommunityChat
  (AddCommunityChat(..)
  , defaultAddCommunityChat
  ) where

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

-- | Adds a chat to a community. If the current user isn't allowed to change the list of chats in the community, then a request to add the chat is sent to administrators of the community instead and the method fails with the error "COMMUNITY_REQUEST_CREATED". Returns 'TD.Data.Ok.Ok'
data AddCommunityChat
  = AddCommunityChat
    { AddCommunityChat -> Maybe Int
community_id :: Maybe Int  -- ^ Identifier of the community
    , AddCommunityChat -> Maybe Int
chat_id      :: Maybe Int  -- ^ Identifier of the chat to add; only chats with owned bots and owned basic group, supergroup and channel chats are allowed; basic group chats will be automatically upgraded to supergroup chats. A community can have up to getOption("community_chat_count_max") supergroup and channel chats and up to getOption("community_bot_count_max") chats with bots; otherwise, the method fails with the error "COMMUNITY_PEERS_TOO_MUCH"
    , AddCommunityChat -> Maybe Bool
is_hidden    :: Maybe Bool -- ^ Pass true if the chat will be visible only to administrators of the community
    }
  deriving (AddCommunityChat -> AddCommunityChat -> Bool
(AddCommunityChat -> AddCommunityChat -> Bool)
-> (AddCommunityChat -> AddCommunityChat -> Bool)
-> Eq AddCommunityChat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AddCommunityChat -> AddCommunityChat -> Bool
== :: AddCommunityChat -> AddCommunityChat -> Bool
$c/= :: AddCommunityChat -> AddCommunityChat -> Bool
/= :: AddCommunityChat -> AddCommunityChat -> Bool
Eq, Int -> AddCommunityChat -> ShowS
[AddCommunityChat] -> ShowS
AddCommunityChat -> String
(Int -> AddCommunityChat -> ShowS)
-> (AddCommunityChat -> String)
-> ([AddCommunityChat] -> ShowS)
-> Show AddCommunityChat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddCommunityChat -> ShowS
showsPrec :: Int -> AddCommunityChat -> ShowS
$cshow :: AddCommunityChat -> String
show :: AddCommunityChat -> String
$cshowList :: [AddCommunityChat] -> ShowS
showList :: [AddCommunityChat] -> ShowS
Show)

instance I.ShortShow AddCommunityChat where
  shortShow :: AddCommunityChat -> String
shortShow
    AddCommunityChat
      { community_id :: AddCommunityChat -> Maybe Int
community_id = Maybe Int
community_id_
      , chat_id :: AddCommunityChat -> Maybe Int
chat_id      = Maybe Int
chat_id_
      , is_hidden :: AddCommunityChat -> Maybe Bool
is_hidden    = Maybe Bool
is_hidden_
      }
        = String
"AddCommunityChat"
          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
"is_hidden"    String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_hidden_
          ]

instance AT.ToJSON AddCommunityChat where
  toJSON :: AddCommunityChat -> Value
toJSON
    AddCommunityChat
      { community_id :: AddCommunityChat -> Maybe Int
community_id = Maybe Int
community_id_
      , chat_id :: AddCommunityChat -> Maybe Int
chat_id      = Maybe Int
chat_id_
      , is_hidden :: AddCommunityChat -> Maybe Bool
is_hidden    = Maybe Bool
is_hidden_
      }
        = [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
"addCommunityChat"
          , 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
"is_hidden"    Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_hidden_
          ]

defaultAddCommunityChat :: AddCommunityChat
defaultAddCommunityChat :: AddCommunityChat
defaultAddCommunityChat =
  AddCommunityChat
    { 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
    , is_hidden :: Maybe Bool
is_hidden    = Maybe Bool
forall a. Maybe a
Nothing
    }