module TD.Data.ChatStatisticsObjectType
  (ChatStatisticsObjectType(..)) where

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

-- | Describes type of object, for which statistics are provided
data ChatStatisticsObjectType
  = ChatStatisticsObjectTypeMessage -- ^ Describes a message sent in the chat
    { ChatStatisticsObjectType -> Maybe Int
message_id :: Maybe Int -- ^ Message identifier
    }
  | ChatStatisticsObjectTypeStory -- ^ Describes a story sent by the chat
    { ChatStatisticsObjectType -> Maybe Int
story_id :: Maybe Int -- ^ Story identifier
    }
  deriving (ChatStatisticsObjectType -> ChatStatisticsObjectType -> Bool
(ChatStatisticsObjectType -> ChatStatisticsObjectType -> Bool)
-> (ChatStatisticsObjectType -> ChatStatisticsObjectType -> Bool)
-> Eq ChatStatisticsObjectType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatStatisticsObjectType -> ChatStatisticsObjectType -> Bool
== :: ChatStatisticsObjectType -> ChatStatisticsObjectType -> Bool
$c/= :: ChatStatisticsObjectType -> ChatStatisticsObjectType -> Bool
/= :: ChatStatisticsObjectType -> ChatStatisticsObjectType -> Bool
Eq, Int -> ChatStatisticsObjectType -> ShowS
[ChatStatisticsObjectType] -> ShowS
ChatStatisticsObjectType -> String
(Int -> ChatStatisticsObjectType -> ShowS)
-> (ChatStatisticsObjectType -> String)
-> ([ChatStatisticsObjectType] -> ShowS)
-> Show ChatStatisticsObjectType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatStatisticsObjectType -> ShowS
showsPrec :: Int -> ChatStatisticsObjectType -> ShowS
$cshow :: ChatStatisticsObjectType -> String
show :: ChatStatisticsObjectType -> String
$cshowList :: [ChatStatisticsObjectType] -> ShowS
showList :: [ChatStatisticsObjectType] -> ShowS
Show)

instance I.ShortShow ChatStatisticsObjectType where
  shortShow :: ChatStatisticsObjectType -> String
shortShow ChatStatisticsObjectTypeMessage
    { message_id :: ChatStatisticsObjectType -> Maybe Int
message_id = Maybe Int
message_id_
    }
      = String
"ChatStatisticsObjectTypeMessage"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
        ]
  shortShow ChatStatisticsObjectTypeStory
    { story_id :: ChatStatisticsObjectType -> Maybe Int
story_id = Maybe Int
story_id_
    }
      = String
"ChatStatisticsObjectTypeStory"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"story_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
story_id_
        ]

instance AT.FromJSON ChatStatisticsObjectType where
  parseJSON :: Value -> Parser ChatStatisticsObjectType
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
"chatStatisticsObjectTypeMessage" -> Value -> Parser ChatStatisticsObjectType
parseChatStatisticsObjectTypeMessage Value
v
      String
"chatStatisticsObjectTypeStory"   -> Value -> Parser ChatStatisticsObjectType
parseChatStatisticsObjectTypeStory Value
v
      String
_                                 -> Parser ChatStatisticsObjectType
forall a. Monoid a => a
mempty
    
    where
      parseChatStatisticsObjectTypeMessage :: A.Value -> AT.Parser ChatStatisticsObjectType
      parseChatStatisticsObjectTypeMessage :: Value -> Parser ChatStatisticsObjectType
parseChatStatisticsObjectTypeMessage = String
-> (Object -> Parser ChatStatisticsObjectType)
-> Value
-> Parser ChatStatisticsObjectType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatStatisticsObjectTypeMessage" ((Object -> Parser ChatStatisticsObjectType)
 -> Value -> Parser ChatStatisticsObjectType)
-> (Object -> Parser ChatStatisticsObjectType)
-> Value
-> Parser ChatStatisticsObjectType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message_id"
        ChatStatisticsObjectType -> Parser ChatStatisticsObjectType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatStatisticsObjectType -> Parser ChatStatisticsObjectType)
-> ChatStatisticsObjectType -> Parser ChatStatisticsObjectType
forall a b. (a -> b) -> a -> b
$ ChatStatisticsObjectTypeMessage
          { message_id :: Maybe Int
message_id = Maybe Int
message_id_
          }
      parseChatStatisticsObjectTypeStory :: A.Value -> AT.Parser ChatStatisticsObjectType
      parseChatStatisticsObjectTypeStory :: Value -> Parser ChatStatisticsObjectType
parseChatStatisticsObjectTypeStory = String
-> (Object -> Parser ChatStatisticsObjectType)
-> Value
-> Parser ChatStatisticsObjectType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatStatisticsObjectTypeStory" ((Object -> Parser ChatStatisticsObjectType)
 -> Value -> Parser ChatStatisticsObjectType)
-> (Object -> Parser ChatStatisticsObjectType)
-> Value
-> Parser ChatStatisticsObjectType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
story_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"story_id"
        ChatStatisticsObjectType -> Parser ChatStatisticsObjectType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatStatisticsObjectType -> Parser ChatStatisticsObjectType)
-> ChatStatisticsObjectType -> Parser ChatStatisticsObjectType
forall a b. (a -> b) -> a -> b
$ ChatStatisticsObjectTypeStory
          { story_id :: Maybe Int
story_id = Maybe Int
story_id_
          }
  parseJSON Value
_ = Parser ChatStatisticsObjectType
forall a. Monoid a => a
mempty