module TD.Data.StoryInteractions
  (StoryInteractions(..)) 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.StoryInteraction as StoryInteraction
import qualified Data.Text as T

data StoryInteractions
  = StoryInteractions -- ^ Represents a list of interactions with a story
    { StoryInteractions -> Maybe Int
total_count          :: Maybe Int                                 -- ^ Approximate total number of interactions found
    , StoryInteractions -> Maybe Int
total_forward_count  :: Maybe Int                                 -- ^ Approximate total number of found forwards and reposts; always 0 for chat stories
    , StoryInteractions -> Maybe Int
total_reaction_count :: Maybe Int                                 -- ^ Approximate total number of found reactions; always 0 for chat stories
    , StoryInteractions -> Maybe [StoryInteraction]
interactions         :: Maybe [StoryInteraction.StoryInteraction] -- ^ List of story interactions
    , StoryInteractions -> Maybe Text
next_offset          :: Maybe T.Text                              -- ^ The offset for the next request. If empty, then there are no more results
    }
  deriving (StoryInteractions -> StoryInteractions -> Bool
(StoryInteractions -> StoryInteractions -> Bool)
-> (StoryInteractions -> StoryInteractions -> Bool)
-> Eq StoryInteractions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StoryInteractions -> StoryInteractions -> Bool
== :: StoryInteractions -> StoryInteractions -> Bool
$c/= :: StoryInteractions -> StoryInteractions -> Bool
/= :: StoryInteractions -> StoryInteractions -> Bool
Eq, Int -> StoryInteractions -> ShowS
[StoryInteractions] -> ShowS
StoryInteractions -> String
(Int -> StoryInteractions -> ShowS)
-> (StoryInteractions -> String)
-> ([StoryInteractions] -> ShowS)
-> Show StoryInteractions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StoryInteractions -> ShowS
showsPrec :: Int -> StoryInteractions -> ShowS
$cshow :: StoryInteractions -> String
show :: StoryInteractions -> String
$cshowList :: [StoryInteractions] -> ShowS
showList :: [StoryInteractions] -> ShowS
Show)

instance I.ShortShow StoryInteractions where
  shortShow :: StoryInteractions -> String
shortShow StoryInteractions
    { total_count :: StoryInteractions -> Maybe Int
total_count          = Maybe Int
total_count_
    , total_forward_count :: StoryInteractions -> Maybe Int
total_forward_count  = Maybe Int
total_forward_count_
    , total_reaction_count :: StoryInteractions -> Maybe Int
total_reaction_count = Maybe Int
total_reaction_count_
    , interactions :: StoryInteractions -> Maybe [StoryInteraction]
interactions         = Maybe [StoryInteraction]
interactions_
    , next_offset :: StoryInteractions -> Maybe Text
next_offset          = Maybe Text
next_offset_
    }
      = String
"StoryInteractions"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"total_count"          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
        , String
"total_forward_count"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_forward_count_
        , String
"total_reaction_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_reaction_count_
        , String
"interactions"         String -> Maybe [StoryInteraction] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [StoryInteraction]
interactions_
        , String
"next_offset"          String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
        ]

instance AT.FromJSON StoryInteractions where
  parseJSON :: Value -> Parser StoryInteractions
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
"storyInteractions" -> Value -> Parser StoryInteractions
parseStoryInteractions Value
v
      String
_                   -> Parser StoryInteractions
forall a. Monoid a => a
mempty
    
    where
      parseStoryInteractions :: A.Value -> AT.Parser StoryInteractions
      parseStoryInteractions :: Value -> Parser StoryInteractions
parseStoryInteractions = String
-> (Object -> Parser StoryInteractions)
-> Value
-> Parser StoryInteractions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryInteractions" ((Object -> Parser StoryInteractions)
 -> Value -> Parser StoryInteractions)
-> (Object -> Parser StoryInteractions)
-> Value
-> Parser StoryInteractions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
total_count_          <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_count"
        Maybe Int
total_forward_count_  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_forward_count"
        Maybe Int
total_reaction_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_reaction_count"
        Maybe [StoryInteraction]
interactions_         <- Object
o Object -> Key -> Parser (Maybe [StoryInteraction])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"interactions"
        Maybe Text
next_offset_          <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_offset"
        StoryInteractions -> Parser StoryInteractions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryInteractions -> Parser StoryInteractions)
-> StoryInteractions -> Parser StoryInteractions
forall a b. (a -> b) -> a -> b
$ StoryInteractions
          { total_count :: Maybe Int
total_count          = Maybe Int
total_count_
          , total_forward_count :: Maybe Int
total_forward_count  = Maybe Int
total_forward_count_
          , total_reaction_count :: Maybe Int
total_reaction_count = Maybe Int
total_reaction_count_
          , interactions :: Maybe [StoryInteraction]
interactions         = Maybe [StoryInteraction]
interactions_
          , next_offset :: Maybe Text
next_offset          = Maybe Text
next_offset_
          }
  parseJSON Value
_ = Parser StoryInteractions
forall a. Monoid a => a
mempty