module Rattletrap.Type.Attribute.ExtendedExplosion where

import qualified Rattletrap.BitGet as BitGet
import qualified Rattletrap.BitPut as BitPut
import qualified Rattletrap.Schema as Schema
import qualified Rattletrap.Type.Attribute.Explosion as Explosion
import qualified Rattletrap.Type.Attribute.FlaggedInt as FlaggedInt
import qualified Rattletrap.Type.Version as Version
import qualified Rattletrap.Utility.Json as Json

data ExtendedExplosion = ExtendedExplosion
  { ExtendedExplosion -> Explosion
explosion :: Explosion.Explosion
  , ExtendedExplosion -> FlaggedInt
unknown :: FlaggedInt.FlaggedInt
  }
  deriving (ExtendedExplosion -> ExtendedExplosion -> Bool
(ExtendedExplosion -> ExtendedExplosion -> Bool)
-> (ExtendedExplosion -> ExtendedExplosion -> Bool)
-> Eq ExtendedExplosion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExtendedExplosion -> ExtendedExplosion -> Bool
$c/= :: ExtendedExplosion -> ExtendedExplosion -> Bool
== :: ExtendedExplosion -> ExtendedExplosion -> Bool
$c== :: ExtendedExplosion -> ExtendedExplosion -> Bool
Eq, Int -> ExtendedExplosion -> ShowS
[ExtendedExplosion] -> ShowS
ExtendedExplosion -> String
(Int -> ExtendedExplosion -> ShowS)
-> (ExtendedExplosion -> String)
-> ([ExtendedExplosion] -> ShowS)
-> Show ExtendedExplosion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExtendedExplosion] -> ShowS
$cshowList :: [ExtendedExplosion] -> ShowS
show :: ExtendedExplosion -> String
$cshow :: ExtendedExplosion -> String
showsPrec :: Int -> ExtendedExplosion -> ShowS
$cshowsPrec :: Int -> ExtendedExplosion -> ShowS
Show)

instance Json.FromJSON ExtendedExplosion where
  parseJSON :: Value -> Parser ExtendedExplosion
parseJSON = String
-> (Object -> Parser ExtendedExplosion)
-> Value
-> Parser ExtendedExplosion
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Json.withObject String
"ExtendedExplosion" ((Object -> Parser ExtendedExplosion)
 -> Value -> Parser ExtendedExplosion)
-> (Object -> Parser ExtendedExplosion)
-> Value
-> Parser ExtendedExplosion
forall a b. (a -> b) -> a -> b
$ \Object
object -> do
    Explosion
explosion <- Object -> String -> Parser Explosion
forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"explosion"
    FlaggedInt
unknown <- Object -> String -> Parser FlaggedInt
forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"unknown"
    ExtendedExplosion -> Parser ExtendedExplosion
forall (f :: * -> *) a. Applicative f => a -> f a
pure ExtendedExplosion :: Explosion -> FlaggedInt -> ExtendedExplosion
ExtendedExplosion { Explosion
explosion :: Explosion
explosion :: Explosion
explosion, FlaggedInt
unknown :: FlaggedInt
unknown :: FlaggedInt
unknown }

instance Json.ToJSON ExtendedExplosion where
  toJSON :: ExtendedExplosion -> Value
toJSON ExtendedExplosion
x = [Pair] -> Value
Json.object
    [String -> Explosion -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"explosion" (Explosion -> Pair) -> Explosion -> Pair
forall a b. (a -> b) -> a -> b
$ ExtendedExplosion -> Explosion
explosion ExtendedExplosion
x, String -> FlaggedInt -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"unknown" (FlaggedInt -> Pair) -> FlaggedInt -> Pair
forall a b. (a -> b) -> a -> b
$ ExtendedExplosion -> FlaggedInt
unknown ExtendedExplosion
x]

schema :: Schema.Schema
schema :: Schema
schema = String -> Value -> Schema
Schema.named String
"attribute-extended-explosion" (Value -> Schema) -> Value -> Schema
forall a b. (a -> b) -> a -> b
$ [(Pair, Bool)] -> Value
Schema.object
  [ (String -> Value -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"explosion" (Value -> Pair) -> Value -> Pair
forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Explosion.schema, Bool
True)
  , (String -> Value -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"unknown" (Value -> Pair) -> Value -> Pair
forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
FlaggedInt.schema, Bool
True)
  ]

bitPut :: ExtendedExplosion -> BitPut.BitPut
bitPut :: ExtendedExplosion -> BitPut
bitPut ExtendedExplosion
x = Explosion -> BitPut
Explosion.bitPut (ExtendedExplosion -> Explosion
explosion ExtendedExplosion
x) BitPut -> BitPut -> BitPut
forall a. Semigroup a => a -> a -> a
<> FlaggedInt -> BitPut
FlaggedInt.bitPut (ExtendedExplosion -> FlaggedInt
unknown ExtendedExplosion
x)

bitGet :: Version.Version -> BitGet.BitGet ExtendedExplosion
bitGet :: Version -> BitGet ExtendedExplosion
bitGet Version
version =
  Explosion -> FlaggedInt -> ExtendedExplosion
ExtendedExplosion (Explosion -> FlaggedInt -> ExtendedExplosion)
-> BitGet Explosion -> BitGet (FlaggedInt -> ExtendedExplosion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version -> BitGet Explosion
Explosion.bitGet Version
version BitGet (FlaggedInt -> ExtendedExplosion)
-> BitGet FlaggedInt -> BitGet ExtendedExplosion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> BitGet FlaggedInt
FlaggedInt.bitGet