module TD.Query.SetChatLocation
  (SetChatLocation(..)
  , defaultSetChatLocation
  ) 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.ChatLocation as ChatLocation

-- | Changes the location of a chat. Available only for some location-based supergroups, use supergroupFullInfo.can_set_location to check whether the method is allowed to use. Returns 'TD.Data.Ok.Ok'
data SetChatLocation
  = SetChatLocation
    { SetChatLocation -> Maybe Int
chat_id  :: Maybe Int                       -- ^ Chat identifier
    , SetChatLocation -> Maybe ChatLocation
location :: Maybe ChatLocation.ChatLocation -- ^ New location for the chat; must be valid and not null
    }
  deriving (SetChatLocation -> SetChatLocation -> Bool
(SetChatLocation -> SetChatLocation -> Bool)
-> (SetChatLocation -> SetChatLocation -> Bool)
-> Eq SetChatLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetChatLocation -> SetChatLocation -> Bool
== :: SetChatLocation -> SetChatLocation -> Bool
$c/= :: SetChatLocation -> SetChatLocation -> Bool
/= :: SetChatLocation -> SetChatLocation -> Bool
Eq, Int -> SetChatLocation -> ShowS
[SetChatLocation] -> ShowS
SetChatLocation -> String
(Int -> SetChatLocation -> ShowS)
-> (SetChatLocation -> String)
-> ([SetChatLocation] -> ShowS)
-> Show SetChatLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetChatLocation -> ShowS
showsPrec :: Int -> SetChatLocation -> ShowS
$cshow :: SetChatLocation -> String
show :: SetChatLocation -> String
$cshowList :: [SetChatLocation] -> ShowS
showList :: [SetChatLocation] -> ShowS
Show)

instance I.ShortShow SetChatLocation where
  shortShow :: SetChatLocation -> String
shortShow
    SetChatLocation
      { chat_id :: SetChatLocation -> Maybe Int
chat_id  = Maybe Int
chat_id_
      , location :: SetChatLocation -> Maybe ChatLocation
location = Maybe ChatLocation
location_
      }
        = String
"SetChatLocation"
          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
"location" String -> Maybe ChatLocation -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatLocation
location_
          ]

instance AT.ToJSON SetChatLocation where
  toJSON :: SetChatLocation -> Value
toJSON
    SetChatLocation
      { chat_id :: SetChatLocation -> Maybe Int
chat_id  = Maybe Int
chat_id_
      , location :: SetChatLocation -> Maybe ChatLocation
location = Maybe ChatLocation
location_
      }
        = [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
"setChatLocation"
          , 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
"location" Key -> Maybe ChatLocation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ChatLocation
location_
          ]

defaultSetChatLocation :: SetChatLocation
defaultSetChatLocation :: SetChatLocation
defaultSetChatLocation =
  SetChatLocation
    { chat_id :: Maybe Int
chat_id  = Maybe Int
forall a. Maybe a
Nothing
    , location :: Maybe ChatLocation
location = Maybe ChatLocation
forall a. Maybe a
Nothing
    }