module TD.Data.ChatActiveStories
  (ChatActiveStories(..)) 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.StoryList as StoryList
import qualified TD.Data.StoryInfo as StoryInfo

data ChatActiveStories
  = ChatActiveStories -- ^ Describes active stories posted by a chat
    { ChatActiveStories -> Maybe Int
chat_id           :: Maybe Int                   -- ^ Identifier of the chat that posted the stories
    , ChatActiveStories -> Maybe StoryList
list              :: Maybe StoryList.StoryList   -- ^ Identifier of the story list in which the stories are shown; may be null if the stories aren't shown in a story list
    , ChatActiveStories -> Maybe Int
order             :: Maybe Int                   -- ^ A parameter used to determine order of the stories in the story list; 0 if the stories doesn't need to be shown in the story list. Stories must be sorted by the pair (order, story_sender_chat_id) in descending order
    , ChatActiveStories -> Maybe Int
max_read_story_id :: Maybe Int                   -- ^ Identifier of the last read active story
    , ChatActiveStories -> Maybe [StoryInfo]
stories           :: Maybe [StoryInfo.StoryInfo] -- ^ Basic information about the stories; use getStory to get full information about the stories. The stories are in chronological order (i.e., in order of increasing story identifiers)
    }
  deriving (ChatActiveStories -> ChatActiveStories -> Bool
(ChatActiveStories -> ChatActiveStories -> Bool)
-> (ChatActiveStories -> ChatActiveStories -> Bool)
-> Eq ChatActiveStories
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatActiveStories -> ChatActiveStories -> Bool
== :: ChatActiveStories -> ChatActiveStories -> Bool
$c/= :: ChatActiveStories -> ChatActiveStories -> Bool
/= :: ChatActiveStories -> ChatActiveStories -> Bool
Eq, Int -> ChatActiveStories -> ShowS
[ChatActiveStories] -> ShowS
ChatActiveStories -> String
(Int -> ChatActiveStories -> ShowS)
-> (ChatActiveStories -> String)
-> ([ChatActiveStories] -> ShowS)
-> Show ChatActiveStories
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatActiveStories -> ShowS
showsPrec :: Int -> ChatActiveStories -> ShowS
$cshow :: ChatActiveStories -> String
show :: ChatActiveStories -> String
$cshowList :: [ChatActiveStories] -> ShowS
showList :: [ChatActiveStories] -> ShowS
Show)

instance I.ShortShow ChatActiveStories where
  shortShow :: ChatActiveStories -> String
shortShow ChatActiveStories
    { chat_id :: ChatActiveStories -> Maybe Int
chat_id           = Maybe Int
chat_id_
    , list :: ChatActiveStories -> Maybe StoryList
list              = Maybe StoryList
list_
    , order :: ChatActiveStories -> Maybe Int
order             = Maybe Int
order_
    , max_read_story_id :: ChatActiveStories -> Maybe Int
max_read_story_id = Maybe Int
max_read_story_id_
    , stories :: ChatActiveStories -> Maybe [StoryInfo]
stories           = Maybe [StoryInfo]
stories_
    }
      = String
"ChatActiveStories"
        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
"list"              String -> Maybe StoryList -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StoryList
list_
        , String
"order"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
order_
        , String
"max_read_story_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
max_read_story_id_
        , String
"stories"           String -> Maybe [StoryInfo] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [StoryInfo]
stories_
        ]

instance AT.FromJSON ChatActiveStories where
  parseJSON :: Value -> Parser ChatActiveStories
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
"chatActiveStories" -> Value -> Parser ChatActiveStories
parseChatActiveStories Value
v
      String
_                   -> Parser ChatActiveStories
forall a. Monoid a => a
mempty
    
    where
      parseChatActiveStories :: A.Value -> AT.Parser ChatActiveStories
      parseChatActiveStories :: Value -> Parser ChatActiveStories
parseChatActiveStories = String
-> (Object -> Parser ChatActiveStories)
-> Value
-> Parser ChatActiveStories
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActiveStories" ((Object -> Parser ChatActiveStories)
 -> Value -> Parser ChatActiveStories)
-> (Object -> Parser ChatActiveStories)
-> Value
-> Parser ChatActiveStories
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
chat_id_           <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_id"
        Maybe StoryList
list_              <- Object
o Object -> Key -> Parser (Maybe StoryList)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"list"
        Maybe Int
order_             <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"order"
        Maybe Int
max_read_story_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"max_read_story_id"
        Maybe [StoryInfo]
stories_           <- Object
o Object -> Key -> Parser (Maybe [StoryInfo])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"stories"
        ChatActiveStories -> Parser ChatActiveStories
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatActiveStories -> Parser ChatActiveStories)
-> ChatActiveStories -> Parser ChatActiveStories
forall a b. (a -> b) -> a -> b
$ ChatActiveStories
          { chat_id :: Maybe Int
chat_id           = Maybe Int
chat_id_
          , list :: Maybe StoryList
list              = Maybe StoryList
list_
          , order :: Maybe Int
order             = Maybe Int
order_
          , max_read_story_id :: Maybe Int
max_read_story_id = Maybe Int
max_read_story_id_
          , stories :: Maybe [StoryInfo]
stories           = Maybe [StoryInfo]
stories_
          }
  parseJSON Value
_ = Parser ChatActiveStories
forall a. Monoid a => a
mempty