module TD.Data.AttributeCraftPersistenceProbability
  (AttributeCraftPersistenceProbability(..)) where

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

data AttributeCraftPersistenceProbability
  = AttributeCraftPersistenceProbability -- ^ Describes chance of the crafted gift to have the backdrop or symbol of one of the original gifts
    { AttributeCraftPersistenceProbability -> Maybe [Int]
persistence_chance_per_mille :: Maybe [Int] -- ^ The 4 numbers that describe probability of the craft result to have the same attribute as one of the original gifts if 1, 2, 3, or 4 gifts with the attribute are used in the craft. Each number represents the number of crafted gifts with the original attribute per 1000 successful craftings
    }
  deriving (AttributeCraftPersistenceProbability
-> AttributeCraftPersistenceProbability -> Bool
(AttributeCraftPersistenceProbability
 -> AttributeCraftPersistenceProbability -> Bool)
-> (AttributeCraftPersistenceProbability
    -> AttributeCraftPersistenceProbability -> Bool)
-> Eq AttributeCraftPersistenceProbability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AttributeCraftPersistenceProbability
-> AttributeCraftPersistenceProbability -> Bool
== :: AttributeCraftPersistenceProbability
-> AttributeCraftPersistenceProbability -> Bool
$c/= :: AttributeCraftPersistenceProbability
-> AttributeCraftPersistenceProbability -> Bool
/= :: AttributeCraftPersistenceProbability
-> AttributeCraftPersistenceProbability -> Bool
Eq, Int -> AttributeCraftPersistenceProbability -> ShowS
[AttributeCraftPersistenceProbability] -> ShowS
AttributeCraftPersistenceProbability -> String
(Int -> AttributeCraftPersistenceProbability -> ShowS)
-> (AttributeCraftPersistenceProbability -> String)
-> ([AttributeCraftPersistenceProbability] -> ShowS)
-> Show AttributeCraftPersistenceProbability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AttributeCraftPersistenceProbability -> ShowS
showsPrec :: Int -> AttributeCraftPersistenceProbability -> ShowS
$cshow :: AttributeCraftPersistenceProbability -> String
show :: AttributeCraftPersistenceProbability -> String
$cshowList :: [AttributeCraftPersistenceProbability] -> ShowS
showList :: [AttributeCraftPersistenceProbability] -> ShowS
Show)

instance I.ShortShow AttributeCraftPersistenceProbability where
  shortShow :: AttributeCraftPersistenceProbability -> String
shortShow AttributeCraftPersistenceProbability
    { persistence_chance_per_mille :: AttributeCraftPersistenceProbability -> Maybe [Int]
persistence_chance_per_mille = Maybe [Int]
persistence_chance_per_mille_
    }
      = String
"AttributeCraftPersistenceProbability"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"persistence_chance_per_mille" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
persistence_chance_per_mille_
        ]

instance AT.FromJSON AttributeCraftPersistenceProbability where
  parseJSON :: Value -> Parser AttributeCraftPersistenceProbability
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
"attributeCraftPersistenceProbability" -> Value -> Parser AttributeCraftPersistenceProbability
parseAttributeCraftPersistenceProbability Value
v
      String
_                                      -> Parser AttributeCraftPersistenceProbability
forall a. Monoid a => a
mempty
    
    where
      parseAttributeCraftPersistenceProbability :: A.Value -> AT.Parser AttributeCraftPersistenceProbability
      parseAttributeCraftPersistenceProbability :: Value -> Parser AttributeCraftPersistenceProbability
parseAttributeCraftPersistenceProbability = String
-> (Object -> Parser AttributeCraftPersistenceProbability)
-> Value
-> Parser AttributeCraftPersistenceProbability
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AttributeCraftPersistenceProbability" ((Object -> Parser AttributeCraftPersistenceProbability)
 -> Value -> Parser AttributeCraftPersistenceProbability)
-> (Object -> Parser AttributeCraftPersistenceProbability)
-> Value
-> Parser AttributeCraftPersistenceProbability
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [Int]
persistence_chance_per_mille_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"persistence_chance_per_mille"
        AttributeCraftPersistenceProbability
-> Parser AttributeCraftPersistenceProbability
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AttributeCraftPersistenceProbability
 -> Parser AttributeCraftPersistenceProbability)
-> AttributeCraftPersistenceProbability
-> Parser AttributeCraftPersistenceProbability
forall a b. (a -> b) -> a -> b
$ AttributeCraftPersistenceProbability
          { persistence_chance_per_mille :: Maybe [Int]
persistence_chance_per_mille = Maybe [Int]
persistence_chance_per_mille_
          }
  parseJSON Value
_ = Parser AttributeCraftPersistenceProbability
forall a. Monoid a => a
mempty