module TD.Query.GetGroupsInCommon
  (GetGroupsInCommon(..)
  , defaultGetGroupsInCommon
  ) where

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

-- | Returns a list of common group chats with a given user. Chats are sorted by their type and creation date. Returns 'TD.Data.Chats.Chats'
data GetGroupsInCommon
  = GetGroupsInCommon
    { GetGroupsInCommon -> Maybe Int
user_id        :: Maybe Int -- ^ User identifier
    , GetGroupsInCommon -> Maybe Int
offset_chat_id :: Maybe Int -- ^ Chat identifier starting from which to return chats; use 0 for the first request
    , GetGroupsInCommon -> Maybe Int
limit          :: Maybe Int -- ^ The maximum number of chats to be returned; up to 100
    }
  deriving (GetGroupsInCommon -> GetGroupsInCommon -> Bool
(GetGroupsInCommon -> GetGroupsInCommon -> Bool)
-> (GetGroupsInCommon -> GetGroupsInCommon -> Bool)
-> Eq GetGroupsInCommon
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetGroupsInCommon -> GetGroupsInCommon -> Bool
== :: GetGroupsInCommon -> GetGroupsInCommon -> Bool
$c/= :: GetGroupsInCommon -> GetGroupsInCommon -> Bool
/= :: GetGroupsInCommon -> GetGroupsInCommon -> Bool
Eq, Int -> GetGroupsInCommon -> ShowS
[GetGroupsInCommon] -> ShowS
GetGroupsInCommon -> String
(Int -> GetGroupsInCommon -> ShowS)
-> (GetGroupsInCommon -> String)
-> ([GetGroupsInCommon] -> ShowS)
-> Show GetGroupsInCommon
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetGroupsInCommon -> ShowS
showsPrec :: Int -> GetGroupsInCommon -> ShowS
$cshow :: GetGroupsInCommon -> String
show :: GetGroupsInCommon -> String
$cshowList :: [GetGroupsInCommon] -> ShowS
showList :: [GetGroupsInCommon] -> ShowS
Show)

instance I.ShortShow GetGroupsInCommon where
  shortShow :: GetGroupsInCommon -> String
shortShow
    GetGroupsInCommon
      { user_id :: GetGroupsInCommon -> Maybe Int
user_id        = Maybe Int
user_id_
      , offset_chat_id :: GetGroupsInCommon -> Maybe Int
offset_chat_id = Maybe Int
offset_chat_id_
      , limit :: GetGroupsInCommon -> Maybe Int
limit          = Maybe Int
limit_
      }
        = String
"GetGroupsInCommon"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"user_id"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
          , String
"offset_chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
offset_chat_id_
          , String
"limit"          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          ]

instance AT.ToJSON GetGroupsInCommon where
  toJSON :: GetGroupsInCommon -> Value
toJSON
    GetGroupsInCommon
      { user_id :: GetGroupsInCommon -> Maybe Int
user_id        = Maybe Int
user_id_
      , offset_chat_id :: GetGroupsInCommon -> Maybe Int
offset_chat_id = Maybe Int
offset_chat_id_
      , limit :: GetGroupsInCommon -> Maybe Int
limit          = Maybe Int
limit_
      }
        = [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
"getGroupsInCommon"
          , Key
"user_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
user_id_
          , Key
"offset_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
offset_chat_id_
          , Key
"limit"          Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
limit_
          ]

defaultGetGroupsInCommon :: GetGroupsInCommon
defaultGetGroupsInCommon :: GetGroupsInCommon
defaultGetGroupsInCommon =
  GetGroupsInCommon
    { user_id :: Maybe Int
user_id        = Maybe Int
forall a. Maybe a
Nothing
    , offset_chat_id :: Maybe Int
offset_chat_id = Maybe Int
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit          = Maybe Int
forall a. Maybe a
Nothing
    }