module Rattletrap.Type.Attribute.PrivateMatchSettings where

import qualified Rattletrap.BitGet as BitGet
import qualified Rattletrap.BitPut as BitPut
import qualified Rattletrap.Schema as Schema
import qualified Rattletrap.Type.Str as Str
import qualified Rattletrap.Type.U32 as U32
import qualified Rattletrap.Utility.Json as Json

data PrivateMatchSettings = PrivateMatchSettings
  { PrivateMatchSettings -> Str
mutators :: Str.Str
  , PrivateMatchSettings -> U32
joinableBy :: U32.U32
  , PrivateMatchSettings -> U32
maxPlayers :: U32.U32
  , PrivateMatchSettings -> Str
gameName :: Str.Str
  , PrivateMatchSettings -> Str
password :: Str.Str
  , PrivateMatchSettings -> Bool
flag :: Bool
  }
  deriving (PrivateMatchSettings -> PrivateMatchSettings -> Bool
(PrivateMatchSettings -> PrivateMatchSettings -> Bool)
-> (PrivateMatchSettings -> PrivateMatchSettings -> Bool)
-> Eq PrivateMatchSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrivateMatchSettings -> PrivateMatchSettings -> Bool
$c/= :: PrivateMatchSettings -> PrivateMatchSettings -> Bool
== :: PrivateMatchSettings -> PrivateMatchSettings -> Bool
$c== :: PrivateMatchSettings -> PrivateMatchSettings -> Bool
Eq, Int -> PrivateMatchSettings -> ShowS
[PrivateMatchSettings] -> ShowS
PrivateMatchSettings -> String
(Int -> PrivateMatchSettings -> ShowS)
-> (PrivateMatchSettings -> String)
-> ([PrivateMatchSettings] -> ShowS)
-> Show PrivateMatchSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrivateMatchSettings] -> ShowS
$cshowList :: [PrivateMatchSettings] -> ShowS
show :: PrivateMatchSettings -> String
$cshow :: PrivateMatchSettings -> String
showsPrec :: Int -> PrivateMatchSettings -> ShowS
$cshowsPrec :: Int -> PrivateMatchSettings -> ShowS
Show)

instance Json.FromJSON PrivateMatchSettings where
  parseJSON :: Value -> Parser PrivateMatchSettings
parseJSON = String
-> (Object -> Parser PrivateMatchSettings)
-> Value
-> Parser PrivateMatchSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Json.withObject String
"PrivateMatchSettings" ((Object -> Parser PrivateMatchSettings)
 -> Value -> Parser PrivateMatchSettings)
-> (Object -> Parser PrivateMatchSettings)
-> Value
-> Parser PrivateMatchSettings
forall a b. (a -> b) -> a -> b
$ \Object
object -> do
    Str
mutators <- Object -> String -> Parser Str
forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"mutators"
    U32
joinableBy <- Object -> String -> Parser U32
forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"joinable_by"
    U32
maxPlayers <- Object -> String -> Parser U32
forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"max_players"
    Str
gameName <- Object -> String -> Parser Str
forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"game_name"
    Str
password <- Object -> String -> Parser Str
forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"password"
    Bool
flag <- Object -> String -> Parser Bool
forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"flag"
    PrivateMatchSettings -> Parser PrivateMatchSettings
forall (f :: * -> *) a. Applicative f => a -> f a
pure PrivateMatchSettings :: Str -> U32 -> U32 -> Str -> Str -> Bool -> PrivateMatchSettings
PrivateMatchSettings
      { Str
mutators :: Str
mutators :: Str
mutators
      , U32
joinableBy :: U32
joinableBy :: U32
joinableBy
      , U32
maxPlayers :: U32
maxPlayers :: U32
maxPlayers
      , Str
gameName :: Str
gameName :: Str
gameName
      , Str
password :: Str
password :: Str
password
      , Bool
flag :: Bool
flag :: Bool
flag
      }

instance Json.ToJSON PrivateMatchSettings where
  toJSON :: PrivateMatchSettings -> Value
toJSON PrivateMatchSettings
x = [Pair] -> Value
Json.object
    [ String -> Str -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"mutators" (Str -> Pair) -> Str -> Pair
forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> Str
mutators PrivateMatchSettings
x
    , String -> U32 -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"joinable_by" (U32 -> Pair) -> U32 -> Pair
forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> U32
joinableBy PrivateMatchSettings
x
    , String -> U32 -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"max_players" (U32 -> Pair) -> U32 -> Pair
forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> U32
maxPlayers PrivateMatchSettings
x
    , String -> Str -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"game_name" (Str -> Pair) -> Str -> Pair
forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> Str
gameName PrivateMatchSettings
x
    , String -> Str -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"password" (Str -> Pair) -> Str -> Pair
forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> Str
password PrivateMatchSettings
x
    , String -> Bool -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"flag" (Bool -> Pair) -> Bool -> Pair
forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> Bool
flag PrivateMatchSettings
x
    ]

schema :: Schema.Schema
schema :: Schema
schema = String -> Value -> Schema
Schema.named String
"attribute-private-match-settings" (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
"mutators" (Value -> Pair) -> Value -> Pair
forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Str.schema, Bool
True)
  , (String -> Value -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"joinable_by" (Value -> Pair) -> Value -> Pair
forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
U32.schema, Bool
True)
  , (String -> Value -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"max_players" (Value -> Pair) -> Value -> Pair
forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
U32.schema, Bool
True)
  , (String -> Value -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"game_name" (Value -> Pair) -> Value -> Pair
forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Str.schema, Bool
True)
  , (String -> Value -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"password" (Value -> Pair) -> Value -> Pair
forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Str.schema, Bool
True)
  , (String -> Value -> Pair
forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"flag" (Value -> Pair) -> Value -> Pair
forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Schema.boolean, Bool
True)
  ]

bitPut :: PrivateMatchSettings -> BitPut.BitPut
bitPut :: PrivateMatchSettings -> BitPut
bitPut PrivateMatchSettings
privateMatchSettingsAttribute =
  Str -> BitPut
Str.bitPut (PrivateMatchSettings -> Str
mutators PrivateMatchSettings
privateMatchSettingsAttribute)
    BitPut -> BitPut -> BitPut
forall a. Semigroup a => a -> a -> a
<> U32 -> BitPut
U32.bitPut (PrivateMatchSettings -> U32
joinableBy PrivateMatchSettings
privateMatchSettingsAttribute)
    BitPut -> BitPut -> BitPut
forall a. Semigroup a => a -> a -> a
<> U32 -> BitPut
U32.bitPut (PrivateMatchSettings -> U32
maxPlayers PrivateMatchSettings
privateMatchSettingsAttribute)
    BitPut -> BitPut -> BitPut
forall a. Semigroup a => a -> a -> a
<> Str -> BitPut
Str.bitPut (PrivateMatchSettings -> Str
gameName PrivateMatchSettings
privateMatchSettingsAttribute)
    BitPut -> BitPut -> BitPut
forall a. Semigroup a => a -> a -> a
<> Str -> BitPut
Str.bitPut (PrivateMatchSettings -> Str
password PrivateMatchSettings
privateMatchSettingsAttribute)
    BitPut -> BitPut -> BitPut
forall a. Semigroup a => a -> a -> a
<> Bool -> BitPut
BitPut.bool (PrivateMatchSettings -> Bool
flag PrivateMatchSettings
privateMatchSettingsAttribute)

bitGet :: BitGet.BitGet PrivateMatchSettings
bitGet :: BitGet PrivateMatchSettings
bitGet = String
-> BitGet PrivateMatchSettings -> BitGet PrivateMatchSettings
forall a. String -> BitGet a -> BitGet a
BitGet.label String
"PrivateMatchSettings" (BitGet PrivateMatchSettings -> BitGet PrivateMatchSettings)
-> BitGet PrivateMatchSettings -> BitGet PrivateMatchSettings
forall a b. (a -> b) -> a -> b
$ do
  Str
mutators <- String -> BitGet Str -> BitGet Str
forall a. String -> BitGet a -> BitGet a
BitGet.label String
"mutators" BitGet Str
Str.bitGet
  U32
joinableBy <- String -> BitGet U32 -> BitGet U32
forall a. String -> BitGet a -> BitGet a
BitGet.label String
"joinableBy" BitGet U32
U32.bitGet
  U32
maxPlayers <- String -> BitGet U32 -> BitGet U32
forall a. String -> BitGet a -> BitGet a
BitGet.label String
"maxPlayers" BitGet U32
U32.bitGet
  Str
gameName <- String -> BitGet Str -> BitGet Str
forall a. String -> BitGet a -> BitGet a
BitGet.label String
"gameName" BitGet Str
Str.bitGet
  Str
password <- String -> BitGet Str -> BitGet Str
forall a. String -> BitGet a -> BitGet a
BitGet.label String
"password" BitGet Str
Str.bitGet
  Bool
flag <- String -> BitGet Bool -> BitGet Bool
forall a. String -> BitGet a -> BitGet a
BitGet.label String
"flag" BitGet Bool
BitGet.bool
  PrivateMatchSettings -> BitGet PrivateMatchSettings
forall (f :: * -> *) a. Applicative f => a -> f a
pure PrivateMatchSettings :: Str -> U32 -> U32 -> Str -> Str -> Bool -> PrivateMatchSettings
PrivateMatchSettings
    { Str
mutators :: Str
mutators :: Str
mutators
    , U32
joinableBy :: U32
joinableBy :: U32
joinableBy
    , U32
maxPlayers :: U32
maxPlayers :: U32
maxPlayers
    , Str
gameName :: Str
gameName :: Str
gameName
    , Str
password :: Str
password :: Str
password
    , Bool
flag :: Bool
flag :: Bool
flag
    }