module TD.Query.SendMessageViewMetrics
  (SendMessageViewMetrics(..)
  , defaultSendMessageViewMetrics
  ) where

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

-- | Informs TDLib about details of a message view by the user from a chat, a message thread or a forum topic history. The method must be called if the message wasn't seen for more than 300 milliseconds, the viewport was destroyed, or the total view duration exceeded 5 minutes. Returns 'TD.Data.Ok.Ok'
data SendMessageViewMetrics
  = SendMessageViewMetrics
    { SendMessageViewMetrics -> Maybe Int
chat_id                            :: Maybe Int -- ^ Chat identifier
    , SendMessageViewMetrics -> Maybe Int
message_id                         :: Maybe Int -- ^ The identifier of the message being viewed
    , SendMessageViewMetrics -> Maybe Int
time_in_view_ms                    :: Maybe Int -- ^ The amount of time the message was seen by at least 1 pixel; in milliseconds
    , SendMessageViewMetrics -> Maybe Int
active_time_in_view_ms             :: Maybe Int -- ^ The amount of time the message was seen by at least 1 pixel within 15 seconds after any action from the user; in milliseconds
    , SendMessageViewMetrics -> Maybe Int
height_to_viewport_ratio_per_mille :: Maybe Int -- ^ The ratio of the post height to the viewport height in 1/1000 fractions
    , SendMessageViewMetrics -> Maybe Int
seen_range_ratio_per_mille         :: Maybe Int -- ^ The ratio of the viewed post height to the full post height in 1/1000 fractions; 0-1000
    }
  deriving (SendMessageViewMetrics -> SendMessageViewMetrics -> Bool
(SendMessageViewMetrics -> SendMessageViewMetrics -> Bool)
-> (SendMessageViewMetrics -> SendMessageViewMetrics -> Bool)
-> Eq SendMessageViewMetrics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SendMessageViewMetrics -> SendMessageViewMetrics -> Bool
== :: SendMessageViewMetrics -> SendMessageViewMetrics -> Bool
$c/= :: SendMessageViewMetrics -> SendMessageViewMetrics -> Bool
/= :: SendMessageViewMetrics -> SendMessageViewMetrics -> Bool
Eq, Int -> SendMessageViewMetrics -> ShowS
[SendMessageViewMetrics] -> ShowS
SendMessageViewMetrics -> String
(Int -> SendMessageViewMetrics -> ShowS)
-> (SendMessageViewMetrics -> String)
-> ([SendMessageViewMetrics] -> ShowS)
-> Show SendMessageViewMetrics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SendMessageViewMetrics -> ShowS
showsPrec :: Int -> SendMessageViewMetrics -> ShowS
$cshow :: SendMessageViewMetrics -> String
show :: SendMessageViewMetrics -> String
$cshowList :: [SendMessageViewMetrics] -> ShowS
showList :: [SendMessageViewMetrics] -> ShowS
Show)

instance I.ShortShow SendMessageViewMetrics where
  shortShow :: SendMessageViewMetrics -> String
shortShow
    SendMessageViewMetrics
      { chat_id :: SendMessageViewMetrics -> Maybe Int
chat_id                            = Maybe Int
chat_id_
      , message_id :: SendMessageViewMetrics -> Maybe Int
message_id                         = Maybe Int
message_id_
      , time_in_view_ms :: SendMessageViewMetrics -> Maybe Int
time_in_view_ms                    = Maybe Int
time_in_view_ms_
      , active_time_in_view_ms :: SendMessageViewMetrics -> Maybe Int
active_time_in_view_ms             = Maybe Int
active_time_in_view_ms_
      , height_to_viewport_ratio_per_mille :: SendMessageViewMetrics -> Maybe Int
height_to_viewport_ratio_per_mille = Maybe Int
height_to_viewport_ratio_per_mille_
      , seen_range_ratio_per_mille :: SendMessageViewMetrics -> Maybe Int
seen_range_ratio_per_mille         = Maybe Int
seen_range_ratio_per_mille_
      }
        = String
"SendMessageViewMetrics"
          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
"message_id"                         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
          , String
"time_in_view_ms"                    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
time_in_view_ms_
          , String
"active_time_in_view_ms"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
active_time_in_view_ms_
          , String
"height_to_viewport_ratio_per_mille" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
height_to_viewport_ratio_per_mille_
          , String
"seen_range_ratio_per_mille"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
seen_range_ratio_per_mille_
          ]

instance AT.ToJSON SendMessageViewMetrics where
  toJSON :: SendMessageViewMetrics -> Value
toJSON
    SendMessageViewMetrics
      { chat_id :: SendMessageViewMetrics -> Maybe Int
chat_id                            = Maybe Int
chat_id_
      , message_id :: SendMessageViewMetrics -> Maybe Int
message_id                         = Maybe Int
message_id_
      , time_in_view_ms :: SendMessageViewMetrics -> Maybe Int
time_in_view_ms                    = Maybe Int
time_in_view_ms_
      , active_time_in_view_ms :: SendMessageViewMetrics -> Maybe Int
active_time_in_view_ms             = Maybe Int
active_time_in_view_ms_
      , height_to_viewport_ratio_per_mille :: SendMessageViewMetrics -> Maybe Int
height_to_viewport_ratio_per_mille = Maybe Int
height_to_viewport_ratio_per_mille_
      , seen_range_ratio_per_mille :: SendMessageViewMetrics -> Maybe Int
seen_range_ratio_per_mille         = Maybe Int
seen_range_ratio_per_mille_
      }
        = [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
"sendMessageViewMetrics"
          , 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
"message_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
message_id_
          , Key
"time_in_view_ms"                    Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
time_in_view_ms_
          , Key
"active_time_in_view_ms"             Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
active_time_in_view_ms_
          , Key
"height_to_viewport_ratio_per_mille" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
height_to_viewport_ratio_per_mille_
          , Key
"seen_range_ratio_per_mille"         Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
seen_range_ratio_per_mille_
          ]

defaultSendMessageViewMetrics :: SendMessageViewMetrics
defaultSendMessageViewMetrics :: SendMessageViewMetrics
defaultSendMessageViewMetrics =
  SendMessageViewMetrics
    { chat_id :: Maybe Int
chat_id                            = Maybe Int
forall a. Maybe a
Nothing
    , message_id :: Maybe Int
message_id                         = Maybe Int
forall a. Maybe a
Nothing
    , time_in_view_ms :: Maybe Int
time_in_view_ms                    = Maybe Int
forall a. Maybe a
Nothing
    , active_time_in_view_ms :: Maybe Int
active_time_in_view_ms             = Maybe Int
forall a. Maybe a
Nothing
    , height_to_viewport_ratio_per_mille :: Maybe Int
height_to_viewport_ratio_per_mille = Maybe Int
forall a. Maybe a
Nothing
    , seen_range_ratio_per_mille :: Maybe Int
seen_range_ratio_per_mille         = Maybe Int
forall a. Maybe a
Nothing
    }