module TD.Query.SetChatPermissions
  (SetChatPermissions(..)
  , defaultSetChatPermissions
  ) where

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

-- | Changes the chat members permissions. Supported only for basic groups and supergroups. Requires can_restrict_members administrator right. Returns 'TD.Data.Ok.Ok'
data SetChatPermissions
  = SetChatPermissions
    { SetChatPermissions -> Maybe Int
chat_id     :: Maybe Int                             -- ^ Chat identifier
    , SetChatPermissions -> Maybe ChatPermissions
permissions :: Maybe ChatPermissions.ChatPermissions -- ^ New non-administrator members permissions in the chat
    }
  deriving (SetChatPermissions -> SetChatPermissions -> Bool
(SetChatPermissions -> SetChatPermissions -> Bool)
-> (SetChatPermissions -> SetChatPermissions -> Bool)
-> Eq SetChatPermissions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetChatPermissions -> SetChatPermissions -> Bool
== :: SetChatPermissions -> SetChatPermissions -> Bool
$c/= :: SetChatPermissions -> SetChatPermissions -> Bool
/= :: SetChatPermissions -> SetChatPermissions -> Bool
Eq, Int -> SetChatPermissions -> ShowS
[SetChatPermissions] -> ShowS
SetChatPermissions -> String
(Int -> SetChatPermissions -> ShowS)
-> (SetChatPermissions -> String)
-> ([SetChatPermissions] -> ShowS)
-> Show SetChatPermissions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetChatPermissions -> ShowS
showsPrec :: Int -> SetChatPermissions -> ShowS
$cshow :: SetChatPermissions -> String
show :: SetChatPermissions -> String
$cshowList :: [SetChatPermissions] -> ShowS
showList :: [SetChatPermissions] -> ShowS
Show)

instance I.ShortShow SetChatPermissions where
  shortShow :: SetChatPermissions -> String
shortShow
    SetChatPermissions
      { chat_id :: SetChatPermissions -> Maybe Int
chat_id     = Maybe Int
chat_id_
      , permissions :: SetChatPermissions -> Maybe ChatPermissions
permissions = Maybe ChatPermissions
permissions_
      }
        = String
"SetChatPermissions"
          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
"permissions" String -> Maybe ChatPermissions -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatPermissions
permissions_
          ]

instance AT.ToJSON SetChatPermissions where
  toJSON :: SetChatPermissions -> Value
toJSON
    SetChatPermissions
      { chat_id :: SetChatPermissions -> Maybe Int
chat_id     = Maybe Int
chat_id_
      , permissions :: SetChatPermissions -> Maybe ChatPermissions
permissions = Maybe ChatPermissions
permissions_
      }
        = [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
"setChatPermissions"
          , 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
"permissions" Key -> Maybe ChatPermissions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ChatPermissions
permissions_
          ]

defaultSetChatPermissions :: SetChatPermissions
defaultSetChatPermissions :: SetChatPermissions
defaultSetChatPermissions =
  SetChatPermissions
    { chat_id :: Maybe Int
chat_id     = Maybe Int
forall a. Maybe a
Nothing
    , permissions :: Maybe ChatPermissions
permissions = Maybe ChatPermissions
forall a. Maybe a
Nothing
    }