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

data AddedReactions
  = AddedReactions -- ^ Represents a list of reactions added to a message
    { AddedReactions -> Maybe Int
total_count :: Maybe Int                           -- ^ The total number of found reactions
    , AddedReactions -> Maybe [AddedReaction]
reactions   :: Maybe [AddedReaction.AddedReaction] -- ^ The list of added reactions
    , AddedReactions -> Maybe Text
next_offset :: Maybe T.Text                        -- ^ The offset for the next request. If empty, then there are no more results
    }
  deriving (AddedReactions -> AddedReactions -> Bool
(AddedReactions -> AddedReactions -> Bool)
-> (AddedReactions -> AddedReactions -> Bool) -> Eq AddedReactions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AddedReactions -> AddedReactions -> Bool
== :: AddedReactions -> AddedReactions -> Bool
$c/= :: AddedReactions -> AddedReactions -> Bool
/= :: AddedReactions -> AddedReactions -> Bool
Eq, Int -> AddedReactions -> ShowS
[AddedReactions] -> ShowS
AddedReactions -> String
(Int -> AddedReactions -> ShowS)
-> (AddedReactions -> String)
-> ([AddedReactions] -> ShowS)
-> Show AddedReactions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddedReactions -> ShowS
showsPrec :: Int -> AddedReactions -> ShowS
$cshow :: AddedReactions -> String
show :: AddedReactions -> String
$cshowList :: [AddedReactions] -> ShowS
showList :: [AddedReactions] -> ShowS
Show)

instance I.ShortShow AddedReactions where
  shortShow :: AddedReactions -> String
shortShow AddedReactions
    { total_count :: AddedReactions -> Maybe Int
total_count = Maybe Int
total_count_
    , reactions :: AddedReactions -> Maybe [AddedReaction]
reactions   = Maybe [AddedReaction]
reactions_
    , next_offset :: AddedReactions -> Maybe Text
next_offset = Maybe Text
next_offset_
    }
      = String
"AddedReactions"
        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
"reactions"   String -> Maybe [AddedReaction] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [AddedReaction]
reactions_
        , String
"next_offset" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
        ]

instance AT.FromJSON AddedReactions where
  parseJSON :: Value -> Parser AddedReactions
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
"addedReactions" -> Value -> Parser AddedReactions
parseAddedReactions Value
v
      String
_                -> Parser AddedReactions
forall a. Monoid a => a
mempty
    
    where
      parseAddedReactions :: A.Value -> AT.Parser AddedReactions
      parseAddedReactions :: Value -> Parser AddedReactions
parseAddedReactions = String
-> (Object -> Parser AddedReactions)
-> Value
-> Parser AddedReactions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AddedReactions" ((Object -> Parser AddedReactions)
 -> Value -> Parser AddedReactions)
-> (Object -> Parser AddedReactions)
-> Value
-> Parser AddedReactions
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 [AddedReaction]
reactions_   <- Object
o Object -> Key -> Parser (Maybe [AddedReaction])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"reactions"
        Maybe Text
next_offset_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_offset"
        AddedReactions -> Parser AddedReactions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AddedReactions -> Parser AddedReactions)
-> AddedReactions -> Parser AddedReactions
forall a b. (a -> b) -> a -> b
$ AddedReactions
          { total_count :: Maybe Int
total_count = Maybe Int
total_count_
          , reactions :: Maybe [AddedReaction]
reactions   = Maybe [AddedReaction]
reactions_
          , next_offset :: Maybe Text
next_offset = Maybe Text
next_offset_
          }
  parseJSON Value
_ = Parser AddedReactions
forall a. Monoid a => a
mempty