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

data PublicForwards
  = PublicForwards -- ^ Represents a list of public forwards and reposts as a story of a message or a story
    { PublicForwards -> Maybe Int
total_count :: Maybe Int                           -- ^ Approximate total number of messages and stories found
    , PublicForwards -> Maybe [PublicForward]
forwards    :: Maybe [PublicForward.PublicForward] -- ^ List of found public forwards and reposts
    , PublicForwards -> Maybe Text
next_offset :: Maybe T.Text                        -- ^ The offset for the next request. If empty, then there are no more results
    }
  deriving (PublicForwards -> PublicForwards -> Bool
(PublicForwards -> PublicForwards -> Bool)
-> (PublicForwards -> PublicForwards -> Bool) -> Eq PublicForwards
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PublicForwards -> PublicForwards -> Bool
== :: PublicForwards -> PublicForwards -> Bool
$c/= :: PublicForwards -> PublicForwards -> Bool
/= :: PublicForwards -> PublicForwards -> Bool
Eq, Int -> PublicForwards -> ShowS
[PublicForwards] -> ShowS
PublicForwards -> String
(Int -> PublicForwards -> ShowS)
-> (PublicForwards -> String)
-> ([PublicForwards] -> ShowS)
-> Show PublicForwards
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PublicForwards -> ShowS
showsPrec :: Int -> PublicForwards -> ShowS
$cshow :: PublicForwards -> String
show :: PublicForwards -> String
$cshowList :: [PublicForwards] -> ShowS
showList :: [PublicForwards] -> ShowS
Show)

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

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