module TD.Query.SaveApplicationLogEvent
  (SaveApplicationLogEvent(..)
  , defaultSaveApplicationLogEvent
  ) 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.JsonValue as JsonValue

-- | Saves application log event on the server. Can be called before authorization. Returns 'TD.Data.Ok.Ok'
data SaveApplicationLogEvent
  = SaveApplicationLogEvent
    { SaveApplicationLogEvent -> Maybe Text
_type   :: Maybe T.Text              -- ^ Event type
    , SaveApplicationLogEvent -> Maybe Int
chat_id :: Maybe Int                 -- ^ Optional chat identifier, associated with the event
    , SaveApplicationLogEvent -> Maybe JsonValue
_data   :: Maybe JsonValue.JsonValue -- ^ The log event data
    }
  deriving (SaveApplicationLogEvent -> SaveApplicationLogEvent -> Bool
(SaveApplicationLogEvent -> SaveApplicationLogEvent -> Bool)
-> (SaveApplicationLogEvent -> SaveApplicationLogEvent -> Bool)
-> Eq SaveApplicationLogEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SaveApplicationLogEvent -> SaveApplicationLogEvent -> Bool
== :: SaveApplicationLogEvent -> SaveApplicationLogEvent -> Bool
$c/= :: SaveApplicationLogEvent -> SaveApplicationLogEvent -> Bool
/= :: SaveApplicationLogEvent -> SaveApplicationLogEvent -> Bool
Eq, Int -> SaveApplicationLogEvent -> ShowS
[SaveApplicationLogEvent] -> ShowS
SaveApplicationLogEvent -> String
(Int -> SaveApplicationLogEvent -> ShowS)
-> (SaveApplicationLogEvent -> String)
-> ([SaveApplicationLogEvent] -> ShowS)
-> Show SaveApplicationLogEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SaveApplicationLogEvent -> ShowS
showsPrec :: Int -> SaveApplicationLogEvent -> ShowS
$cshow :: SaveApplicationLogEvent -> String
show :: SaveApplicationLogEvent -> String
$cshowList :: [SaveApplicationLogEvent] -> ShowS
showList :: [SaveApplicationLogEvent] -> ShowS
Show)

instance I.ShortShow SaveApplicationLogEvent where
  shortShow :: SaveApplicationLogEvent -> String
shortShow
    SaveApplicationLogEvent
      { _type :: SaveApplicationLogEvent -> Maybe Text
_type   = Maybe Text
_type_
      , chat_id :: SaveApplicationLogEvent -> Maybe Int
chat_id = Maybe Int
chat_id_
      , _data :: SaveApplicationLogEvent -> Maybe JsonValue
_data   = Maybe JsonValue
_data_
      }
        = String
"SaveApplicationLogEvent"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"_type"   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_type_
          , String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"_data"   String -> Maybe JsonValue -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe JsonValue
_data_
          ]

instance AT.ToJSON SaveApplicationLogEvent where
  toJSON :: SaveApplicationLogEvent -> Value
toJSON
    SaveApplicationLogEvent
      { _type :: SaveApplicationLogEvent -> Maybe Text
_type   = Maybe Text
_type_
      , chat_id :: SaveApplicationLogEvent -> Maybe Int
chat_id = Maybe Int
chat_id_
      , _data :: SaveApplicationLogEvent -> Maybe JsonValue
_data   = Maybe JsonValue
_data_
      }
        = [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
"saveApplicationLogEvent"
          , Key
"type"    Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
_type_
          , 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
"data"    Key -> Maybe JsonValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe JsonValue
_data_
          ]

defaultSaveApplicationLogEvent :: SaveApplicationLogEvent
defaultSaveApplicationLogEvent :: SaveApplicationLogEvent
defaultSaveApplicationLogEvent =
  SaveApplicationLogEvent
    { _type :: Maybe Text
_type   = Maybe Text
forall a. Maybe a
Nothing
    , chat_id :: Maybe Int
chat_id = Maybe Int
forall a. Maybe a
Nothing
    , _data :: Maybe JsonValue
_data   = Maybe JsonValue
forall a. Maybe a
Nothing
    }