module TD.Query.CreateCommunity
  (CreateCommunity(..)
  , defaultCreateCommunity
  ) 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

-- | Creates a new community for the given chat. Returns identifier of the created community. Returns 'TD.Data.CommunityId.CommunityId'
data CreateCommunity
  = CreateCommunity
    { CreateCommunity -> Maybe Text
name           :: Maybe T.Text -- ^ Name of the new community
    , CreateCommunity -> Maybe Int
chat_id        :: Maybe Int    -- ^ Identifier of the chat in the community; 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
    , CreateCommunity -> Maybe Bool
is_chat_hidden :: Maybe Bool   -- ^ Pass true if the chat will be visible only to administrators of the community
    }
  deriving (CreateCommunity -> CreateCommunity -> Bool
(CreateCommunity -> CreateCommunity -> Bool)
-> (CreateCommunity -> CreateCommunity -> Bool)
-> Eq CreateCommunity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CreateCommunity -> CreateCommunity -> Bool
== :: CreateCommunity -> CreateCommunity -> Bool
$c/= :: CreateCommunity -> CreateCommunity -> Bool
/= :: CreateCommunity -> CreateCommunity -> Bool
Eq, Int -> CreateCommunity -> ShowS
[CreateCommunity] -> ShowS
CreateCommunity -> String
(Int -> CreateCommunity -> ShowS)
-> (CreateCommunity -> String)
-> ([CreateCommunity] -> ShowS)
-> Show CreateCommunity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CreateCommunity -> ShowS
showsPrec :: Int -> CreateCommunity -> ShowS
$cshow :: CreateCommunity -> String
show :: CreateCommunity -> String
$cshowList :: [CreateCommunity] -> ShowS
showList :: [CreateCommunity] -> ShowS
Show)

instance I.ShortShow CreateCommunity where
  shortShow :: CreateCommunity -> String
shortShow
    CreateCommunity
      { name :: CreateCommunity -> Maybe Text
name           = Maybe Text
name_
      , chat_id :: CreateCommunity -> Maybe Int
chat_id        = Maybe Int
chat_id_
      , is_chat_hidden :: CreateCommunity -> Maybe Bool
is_chat_hidden = Maybe Bool
is_chat_hidden_
      }
        = String
"CreateCommunity"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"name"           String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
          , String
"chat_id"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"is_chat_hidden" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_chat_hidden_
          ]

instance AT.ToJSON CreateCommunity where
  toJSON :: CreateCommunity -> Value
toJSON
    CreateCommunity
      { name :: CreateCommunity -> Maybe Text
name           = Maybe Text
name_
      , chat_id :: CreateCommunity -> Maybe Int
chat_id        = Maybe Int
chat_id_
      , is_chat_hidden :: CreateCommunity -> Maybe Bool
is_chat_hidden = Maybe Bool
is_chat_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
"createCommunity"
          , Key
"name"           Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
name_
          , 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_chat_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_chat_hidden_
          ]

defaultCreateCommunity :: CreateCommunity
defaultCreateCommunity :: CreateCommunity
defaultCreateCommunity =
  CreateCommunity
    { name :: Maybe Text
name           = Maybe Text
forall a. Maybe a
Nothing
    , chat_id :: Maybe Int
chat_id        = Maybe Int
forall a. Maybe a
Nothing
    , is_chat_hidden :: Maybe Bool
is_chat_hidden = Maybe Bool
forall a. Maybe a
Nothing
    }