module TD.Data.UpgradedGiftModel
  (UpgradedGiftModel(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.Sticker as Sticker

data UpgradedGiftModel
  = UpgradedGiftModel -- ^ Describes a model of an upgraded gift
    { UpgradedGiftModel -> Maybe Text
name             :: Maybe T.Text          -- ^ Name of the model
    , UpgradedGiftModel -> Maybe Sticker
sticker          :: Maybe Sticker.Sticker -- ^ The sticker representing the upgraded gift
    , UpgradedGiftModel -> Maybe Int
rarity_per_mille :: Maybe Int             -- ^ The number of upgraded gift that receive this model for each 1000 gifts upgraded
    }
  deriving (UpgradedGiftModel -> UpgradedGiftModel -> Bool
(UpgradedGiftModel -> UpgradedGiftModel -> Bool)
-> (UpgradedGiftModel -> UpgradedGiftModel -> Bool)
-> Eq UpgradedGiftModel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UpgradedGiftModel -> UpgradedGiftModel -> Bool
== :: UpgradedGiftModel -> UpgradedGiftModel -> Bool
$c/= :: UpgradedGiftModel -> UpgradedGiftModel -> Bool
/= :: UpgradedGiftModel -> UpgradedGiftModel -> Bool
Eq, Int -> UpgradedGiftModel -> ShowS
[UpgradedGiftModel] -> ShowS
UpgradedGiftModel -> String
(Int -> UpgradedGiftModel -> ShowS)
-> (UpgradedGiftModel -> String)
-> ([UpgradedGiftModel] -> ShowS)
-> Show UpgradedGiftModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UpgradedGiftModel -> ShowS
showsPrec :: Int -> UpgradedGiftModel -> ShowS
$cshow :: UpgradedGiftModel -> String
show :: UpgradedGiftModel -> String
$cshowList :: [UpgradedGiftModel] -> ShowS
showList :: [UpgradedGiftModel] -> ShowS
Show)

instance I.ShortShow UpgradedGiftModel where
  shortShow :: UpgradedGiftModel -> String
shortShow UpgradedGiftModel
    { name :: UpgradedGiftModel -> Maybe Text
name             = Maybe Text
name_
    , sticker :: UpgradedGiftModel -> Maybe Sticker
sticker          = Maybe Sticker
sticker_
    , rarity_per_mille :: UpgradedGiftModel -> Maybe Int
rarity_per_mille = Maybe Int
rarity_per_mille_
    }
      = String
"UpgradedGiftModel"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"name"             String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
        , String
"sticker"          String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
sticker_
        , String
"rarity_per_mille" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
rarity_per_mille_
        ]

instance AT.FromJSON UpgradedGiftModel where
  parseJSON :: Value -> Parser UpgradedGiftModel
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
"upgradedGiftModel" -> Value -> Parser UpgradedGiftModel
parseUpgradedGiftModel Value
v
      String
_                   -> Parser UpgradedGiftModel
forall a. Monoid a => a
mempty
    
    where
      parseUpgradedGiftModel :: A.Value -> AT.Parser UpgradedGiftModel
      parseUpgradedGiftModel :: Value -> Parser UpgradedGiftModel
parseUpgradedGiftModel = String
-> (Object -> Parser UpgradedGiftModel)
-> Value
-> Parser UpgradedGiftModel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UpgradedGiftModel" ((Object -> Parser UpgradedGiftModel)
 -> Value -> Parser UpgradedGiftModel)
-> (Object -> Parser UpgradedGiftModel)
-> Value
-> Parser UpgradedGiftModel
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
name_             <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"name"
        Maybe Sticker
sticker_          <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sticker"
        Maybe Int
rarity_per_mille_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"rarity_per_mille"
        UpgradedGiftModel -> Parser UpgradedGiftModel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UpgradedGiftModel -> Parser UpgradedGiftModel)
-> UpgradedGiftModel -> Parser UpgradedGiftModel
forall a b. (a -> b) -> a -> b
$ UpgradedGiftModel
          { name :: Maybe Text
name             = Maybe Text
name_
          , sticker :: Maybe Sticker
sticker          = Maybe Sticker
sticker_
          , rarity_per_mille :: Maybe Int
rarity_per_mille = Maybe Int
rarity_per_mille_
          }
  parseJSON Value
_ = Parser UpgradedGiftModel
forall a. Monoid a => a
mempty