module TD.Data.ChatStatisticsInteractionInfo
  (ChatStatisticsInteractionInfo(..)) 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.ChatStatisticsObjectType as ChatStatisticsObjectType

data ChatStatisticsInteractionInfo
  = ChatStatisticsInteractionInfo -- ^ Contains statistics about interactions with a message sent in the chat or a story sent by the chat
    { ChatStatisticsInteractionInfo -> Maybe ChatStatisticsObjectType
object_type    :: Maybe ChatStatisticsObjectType.ChatStatisticsObjectType -- ^ Type of the object
    , ChatStatisticsInteractionInfo -> Maybe Int
view_count     :: Maybe Int                                               -- ^ Number of times the object was viewed
    , ChatStatisticsInteractionInfo -> Maybe Int
forward_count  :: Maybe Int                                               -- ^ Number of times the object was forwarded
    , ChatStatisticsInteractionInfo -> Maybe Int
reaction_count :: Maybe Int                                               -- ^ Number of times reactions were added to the object
    }
  deriving (ChatStatisticsInteractionInfo
-> ChatStatisticsInteractionInfo -> Bool
(ChatStatisticsInteractionInfo
 -> ChatStatisticsInteractionInfo -> Bool)
-> (ChatStatisticsInteractionInfo
    -> ChatStatisticsInteractionInfo -> Bool)
-> Eq ChatStatisticsInteractionInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatStatisticsInteractionInfo
-> ChatStatisticsInteractionInfo -> Bool
== :: ChatStatisticsInteractionInfo
-> ChatStatisticsInteractionInfo -> Bool
$c/= :: ChatStatisticsInteractionInfo
-> ChatStatisticsInteractionInfo -> Bool
/= :: ChatStatisticsInteractionInfo
-> ChatStatisticsInteractionInfo -> Bool
Eq, Int -> ChatStatisticsInteractionInfo -> ShowS
[ChatStatisticsInteractionInfo] -> ShowS
ChatStatisticsInteractionInfo -> String
(Int -> ChatStatisticsInteractionInfo -> ShowS)
-> (ChatStatisticsInteractionInfo -> String)
-> ([ChatStatisticsInteractionInfo] -> ShowS)
-> Show ChatStatisticsInteractionInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatStatisticsInteractionInfo -> ShowS
showsPrec :: Int -> ChatStatisticsInteractionInfo -> ShowS
$cshow :: ChatStatisticsInteractionInfo -> String
show :: ChatStatisticsInteractionInfo -> String
$cshowList :: [ChatStatisticsInteractionInfo] -> ShowS
showList :: [ChatStatisticsInteractionInfo] -> ShowS
Show)

instance I.ShortShow ChatStatisticsInteractionInfo where
  shortShow :: ChatStatisticsInteractionInfo -> String
shortShow ChatStatisticsInteractionInfo
    { object_type :: ChatStatisticsInteractionInfo -> Maybe ChatStatisticsObjectType
object_type    = Maybe ChatStatisticsObjectType
object_type_
    , view_count :: ChatStatisticsInteractionInfo -> Maybe Int
view_count     = Maybe Int
view_count_
    , forward_count :: ChatStatisticsInteractionInfo -> Maybe Int
forward_count  = Maybe Int
forward_count_
    , reaction_count :: ChatStatisticsInteractionInfo -> Maybe Int
reaction_count = Maybe Int
reaction_count_
    }
      = String
"ChatStatisticsInteractionInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"object_type"    String -> Maybe ChatStatisticsObjectType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatStatisticsObjectType
object_type_
        , String
"view_count"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
view_count_
        , String
"forward_count"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
forward_count_
        , String
"reaction_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
reaction_count_
        ]

instance AT.FromJSON ChatStatisticsInteractionInfo where
  parseJSON :: Value -> Parser ChatStatisticsInteractionInfo
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"chatStatisticsInteractionInfo" -> Value -> Parser ChatStatisticsInteractionInfo
parseChatStatisticsInteractionInfo Value
v
      String
_                               -> Parser ChatStatisticsInteractionInfo
forall a. Monoid a => a
mempty
    
    where
      parseChatStatisticsInteractionInfo :: A.Value -> AT.Parser ChatStatisticsInteractionInfo
      parseChatStatisticsInteractionInfo :: Value -> Parser ChatStatisticsInteractionInfo
parseChatStatisticsInteractionInfo = String
-> (Object -> Parser ChatStatisticsInteractionInfo)
-> Value
-> Parser ChatStatisticsInteractionInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatStatisticsInteractionInfo" ((Object -> Parser ChatStatisticsInteractionInfo)
 -> Value -> Parser ChatStatisticsInteractionInfo)
-> (Object -> Parser ChatStatisticsInteractionInfo)
-> Value
-> Parser ChatStatisticsInteractionInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe ChatStatisticsObjectType
object_type_    <- Object
o Object -> Key -> Parser (Maybe ChatStatisticsObjectType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"object_type"
        Maybe Int
view_count_     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"view_count"
        Maybe Int
forward_count_  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"forward_count"
        Maybe Int
reaction_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"reaction_count"
        ChatStatisticsInteractionInfo
-> Parser ChatStatisticsInteractionInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatStatisticsInteractionInfo
 -> Parser ChatStatisticsInteractionInfo)
-> ChatStatisticsInteractionInfo
-> Parser ChatStatisticsInteractionInfo
forall a b. (a -> b) -> a -> b
$ ChatStatisticsInteractionInfo
          { object_type :: Maybe ChatStatisticsObjectType
object_type    = Maybe ChatStatisticsObjectType
object_type_
          , view_count :: Maybe Int
view_count     = Maybe Int
view_count_
          , forward_count :: Maybe Int
forward_count  = Maybe Int
forward_count_
          , reaction_count :: Maybe Int
reaction_count = Maybe Int
reaction_count_
          }
  parseJSON Value
_ = Parser ChatStatisticsInteractionInfo
forall a. Monoid a => a
mempty