module TD.Data.UpgradedGiftBackdropCount
  (UpgradedGiftBackdropCount(..)) 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.UpgradedGiftBackdrop as UpgradedGiftBackdrop

data UpgradedGiftBackdropCount
  = UpgradedGiftBackdropCount -- ^ Describes a backdrop of an upgraded gift
    { UpgradedGiftBackdropCount -> Maybe UpgradedGiftBackdrop
backdrop    :: Maybe UpgradedGiftBackdrop.UpgradedGiftBackdrop -- ^ The backdrop
    , UpgradedGiftBackdropCount -> Maybe Int
total_count :: Maybe Int                                       -- ^ Total number of gifts with the symbol
    }
  deriving (UpgradedGiftBackdropCount -> UpgradedGiftBackdropCount -> Bool
(UpgradedGiftBackdropCount -> UpgradedGiftBackdropCount -> Bool)
-> (UpgradedGiftBackdropCount -> UpgradedGiftBackdropCount -> Bool)
-> Eq UpgradedGiftBackdropCount
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UpgradedGiftBackdropCount -> UpgradedGiftBackdropCount -> Bool
== :: UpgradedGiftBackdropCount -> UpgradedGiftBackdropCount -> Bool
$c/= :: UpgradedGiftBackdropCount -> UpgradedGiftBackdropCount -> Bool
/= :: UpgradedGiftBackdropCount -> UpgradedGiftBackdropCount -> Bool
Eq, Int -> UpgradedGiftBackdropCount -> ShowS
[UpgradedGiftBackdropCount] -> ShowS
UpgradedGiftBackdropCount -> String
(Int -> UpgradedGiftBackdropCount -> ShowS)
-> (UpgradedGiftBackdropCount -> String)
-> ([UpgradedGiftBackdropCount] -> ShowS)
-> Show UpgradedGiftBackdropCount
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UpgradedGiftBackdropCount -> ShowS
showsPrec :: Int -> UpgradedGiftBackdropCount -> ShowS
$cshow :: UpgradedGiftBackdropCount -> String
show :: UpgradedGiftBackdropCount -> String
$cshowList :: [UpgradedGiftBackdropCount] -> ShowS
showList :: [UpgradedGiftBackdropCount] -> ShowS
Show)

instance I.ShortShow UpgradedGiftBackdropCount where
  shortShow :: UpgradedGiftBackdropCount -> String
shortShow UpgradedGiftBackdropCount
    { backdrop :: UpgradedGiftBackdropCount -> Maybe UpgradedGiftBackdrop
backdrop    = Maybe UpgradedGiftBackdrop
backdrop_
    , total_count :: UpgradedGiftBackdropCount -> Maybe Int
total_count = Maybe Int
total_count_
    }
      = String
"UpgradedGiftBackdropCount"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"backdrop"    String -> Maybe UpgradedGiftBackdrop -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftBackdrop
backdrop_
        , String
"total_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
        ]

instance AT.FromJSON UpgradedGiftBackdropCount where
  parseJSON :: Value -> Parser UpgradedGiftBackdropCount
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
"upgradedGiftBackdropCount" -> Value -> Parser UpgradedGiftBackdropCount
parseUpgradedGiftBackdropCount Value
v
      String
_                           -> Parser UpgradedGiftBackdropCount
forall a. Monoid a => a
mempty
    
    where
      parseUpgradedGiftBackdropCount :: A.Value -> AT.Parser UpgradedGiftBackdropCount
      parseUpgradedGiftBackdropCount :: Value -> Parser UpgradedGiftBackdropCount
parseUpgradedGiftBackdropCount = String
-> (Object -> Parser UpgradedGiftBackdropCount)
-> Value
-> Parser UpgradedGiftBackdropCount
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UpgradedGiftBackdropCount" ((Object -> Parser UpgradedGiftBackdropCount)
 -> Value -> Parser UpgradedGiftBackdropCount)
-> (Object -> Parser UpgradedGiftBackdropCount)
-> Value
-> Parser UpgradedGiftBackdropCount
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe UpgradedGiftBackdrop
backdrop_    <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftBackdrop)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"backdrop"
        Maybe Int
total_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_count"
        UpgradedGiftBackdropCount -> Parser UpgradedGiftBackdropCount
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UpgradedGiftBackdropCount -> Parser UpgradedGiftBackdropCount)
-> UpgradedGiftBackdropCount -> Parser UpgradedGiftBackdropCount
forall a b. (a -> b) -> a -> b
$ UpgradedGiftBackdropCount
          { backdrop :: Maybe UpgradedGiftBackdrop
backdrop    = Maybe UpgradedGiftBackdrop
backdrop_
          , total_count :: Maybe Int
total_count = Maybe Int
total_count_
          }
  parseJSON Value
_ = Parser UpgradedGiftBackdropCount
forall a. Monoid a => a
mempty