module TD.Data.UpgradedGiftModelCount
  (UpgradedGiftModelCount(..)) 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.UpgradedGiftModel as UpgradedGiftModel

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

instance I.ShortShow UpgradedGiftModelCount where
  shortShow :: UpgradedGiftModelCount -> String
shortShow UpgradedGiftModelCount
    { model :: UpgradedGiftModelCount -> Maybe UpgradedGiftModel
model       = Maybe UpgradedGiftModel
model_
    , total_count :: UpgradedGiftModelCount -> Maybe Int
total_count = Maybe Int
total_count_
    }
      = String
"UpgradedGiftModelCount"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"model"       String -> Maybe UpgradedGiftModel -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftModel
model_
        , String
"total_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
        ]

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