module TD.Data.StickerSets
  (StickerSets(..)) 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.StickerSetInfo as StickerSetInfo

data StickerSets
  = StickerSets -- ^ Represents a list of sticker sets
    { StickerSets -> Maybe Int
total_count :: Maybe Int                             -- ^ Approximate total number of sticker sets found
    , StickerSets -> Maybe [StickerSetInfo]
sets        :: Maybe [StickerSetInfo.StickerSetInfo] -- ^ List of sticker sets
    }
  deriving (StickerSets -> StickerSets -> Bool
(StickerSets -> StickerSets -> Bool)
-> (StickerSets -> StickerSets -> Bool) -> Eq StickerSets
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StickerSets -> StickerSets -> Bool
== :: StickerSets -> StickerSets -> Bool
$c/= :: StickerSets -> StickerSets -> Bool
/= :: StickerSets -> StickerSets -> Bool
Eq, Int -> StickerSets -> ShowS
[StickerSets] -> ShowS
StickerSets -> String
(Int -> StickerSets -> ShowS)
-> (StickerSets -> String)
-> ([StickerSets] -> ShowS)
-> Show StickerSets
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StickerSets -> ShowS
showsPrec :: Int -> StickerSets -> ShowS
$cshow :: StickerSets -> String
show :: StickerSets -> String
$cshowList :: [StickerSets] -> ShowS
showList :: [StickerSets] -> ShowS
Show)

instance I.ShortShow StickerSets where
  shortShow :: StickerSets -> String
shortShow StickerSets
    { total_count :: StickerSets -> Maybe Int
total_count = Maybe Int
total_count_
    , sets :: StickerSets -> Maybe [StickerSetInfo]
sets        = Maybe [StickerSetInfo]
sets_
    }
      = String
"StickerSets"
        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
"sets"        String -> Maybe [StickerSetInfo] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [StickerSetInfo]
sets_
        ]

instance AT.FromJSON StickerSets where
  parseJSON :: Value -> Parser StickerSets
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
"stickerSets" -> Value -> Parser StickerSets
parseStickerSets Value
v
      String
_             -> Parser StickerSets
forall a. Monoid a => a
mempty
    
    where
      parseStickerSets :: A.Value -> AT.Parser StickerSets
      parseStickerSets :: Value -> Parser StickerSets
parseStickerSets = String
-> (Object -> Parser StickerSets) -> Value -> Parser StickerSets
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StickerSets" ((Object -> Parser StickerSets) -> Value -> Parser StickerSets)
-> (Object -> Parser StickerSets) -> Value -> Parser StickerSets
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 [StickerSetInfo]
sets_        <- Object
o Object -> Key -> Parser (Maybe [StickerSetInfo])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sets"
        StickerSets -> Parser StickerSets
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StickerSets -> Parser StickerSets)
-> StickerSets -> Parser StickerSets
forall a b. (a -> b) -> a -> b
$ StickerSets
          { total_count :: Maybe Int
total_count = Maybe Int
total_count_
          , sets :: Maybe [StickerSetInfo]
sets        = Maybe [StickerSetInfo]
sets_
          }
  parseJSON Value
_ = Parser StickerSets
forall a. Monoid a => a
mempty