module TD.Query.GetChatEventLog
  (GetChatEventLog(..)
  , defaultGetChatEventLog
  ) 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
import qualified TD.Data.ChatEventLogFilters as ChatEventLogFilters

-- | Returns a list of service actions taken by chat members and administrators in the last 48 hours. Available only for supergroups and channels. Requires administrator rights. Returns results in reverse chronological order (i.e., in order of decreasing event_id). Returns 'TD.Data.ChatEvents.ChatEvents'
data GetChatEventLog
  = GetChatEventLog
    { GetChatEventLog -> Maybe Int
chat_id       :: Maybe Int                                     -- ^ Chat identifier
    , GetChatEventLog -> Maybe Text
query         :: Maybe T.Text                                  -- ^ Search query by which to filter events
    , GetChatEventLog -> Maybe Int
from_event_id :: Maybe Int                                     -- ^ Identifier of an event from which to return results. Use 0 to get results from the latest events
    , GetChatEventLog -> Maybe Int
limit         :: Maybe Int                                     -- ^ The maximum number of events to return; up to 100
    , GetChatEventLog -> Maybe ChatEventLogFilters
filters       :: Maybe ChatEventLogFilters.ChatEventLogFilters -- ^ The types of events to return; pass null to get chat events of all types
    , GetChatEventLog -> Maybe [Int]
user_ids      :: Maybe [Int]                                   -- ^ User identifiers by which to filter events. By default, events relating to all users will be returned
    }
  deriving (GetChatEventLog -> GetChatEventLog -> Bool
(GetChatEventLog -> GetChatEventLog -> Bool)
-> (GetChatEventLog -> GetChatEventLog -> Bool)
-> Eq GetChatEventLog
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetChatEventLog -> GetChatEventLog -> Bool
== :: GetChatEventLog -> GetChatEventLog -> Bool
$c/= :: GetChatEventLog -> GetChatEventLog -> Bool
/= :: GetChatEventLog -> GetChatEventLog -> Bool
Eq, Int -> GetChatEventLog -> ShowS
[GetChatEventLog] -> ShowS
GetChatEventLog -> String
(Int -> GetChatEventLog -> ShowS)
-> (GetChatEventLog -> String)
-> ([GetChatEventLog] -> ShowS)
-> Show GetChatEventLog
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetChatEventLog -> ShowS
showsPrec :: Int -> GetChatEventLog -> ShowS
$cshow :: GetChatEventLog -> String
show :: GetChatEventLog -> String
$cshowList :: [GetChatEventLog] -> ShowS
showList :: [GetChatEventLog] -> ShowS
Show)

instance I.ShortShow GetChatEventLog where
  shortShow :: GetChatEventLog -> String
shortShow
    GetChatEventLog
      { chat_id :: GetChatEventLog -> Maybe Int
chat_id       = Maybe Int
chat_id_
      , query :: GetChatEventLog -> Maybe Text
query         = Maybe Text
query_
      , from_event_id :: GetChatEventLog -> Maybe Int
from_event_id = Maybe Int
from_event_id_
      , limit :: GetChatEventLog -> Maybe Int
limit         = Maybe Int
limit_
      , filters :: GetChatEventLog -> Maybe ChatEventLogFilters
filters       = Maybe ChatEventLogFilters
filters_
      , user_ids :: GetChatEventLog -> Maybe [Int]
user_ids      = Maybe [Int]
user_ids_
      }
        = String
"GetChatEventLog"
          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
"query"         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
query_
          , String
"from_event_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
from_event_id_
          , String
"limit"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          , String
"filters"       String -> Maybe ChatEventLogFilters -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatEventLogFilters
filters_
          , String
"user_ids"      String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
user_ids_
          ]

instance AT.ToJSON GetChatEventLog where
  toJSON :: GetChatEventLog -> Value
toJSON
    GetChatEventLog
      { chat_id :: GetChatEventLog -> Maybe Int
chat_id       = Maybe Int
chat_id_
      , query :: GetChatEventLog -> Maybe Text
query         = Maybe Text
query_
      , from_event_id :: GetChatEventLog -> Maybe Int
from_event_id = Maybe Int
from_event_id_
      , limit :: GetChatEventLog -> Maybe Int
limit         = Maybe Int
limit_
      , filters :: GetChatEventLog -> Maybe ChatEventLogFilters
filters       = Maybe ChatEventLogFilters
filters_
      , user_ids :: GetChatEventLog -> Maybe [Int]
user_ids      = Maybe [Int]
user_ids_
      }
        = [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
"getChatEventLog"
          , 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
"query"         Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
query_
          , Key
"from_event_id" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64  Maybe Int
from_event_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_
          , Key
"filters"       Key -> Maybe ChatEventLogFilters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ChatEventLogFilters
filters_
          , Key
"user_ids"      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_ids_
          ]

defaultGetChatEventLog :: GetChatEventLog
defaultGetChatEventLog :: GetChatEventLog
defaultGetChatEventLog =
  GetChatEventLog
    { chat_id :: Maybe Int
chat_id       = Maybe Int
forall a. Maybe a
Nothing
    , query :: Maybe Text
query         = Maybe Text
forall a. Maybe a
Nothing
    , from_event_id :: Maybe Int
from_event_id = Maybe Int
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit         = Maybe Int
forall a. Maybe a
Nothing
    , filters :: Maybe ChatEventLogFilters
filters       = Maybe ChatEventLogFilters
forall a. Maybe a
Nothing
    , user_ids :: Maybe [Int]
user_ids      = Maybe [Int]
forall a. Maybe a
Nothing
    }