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
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
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 = forall a. String -> (Object -> Parser a) -> Value -> Parser a
Json.withObject String
"PrivateMatchSettings" forall a b. (a -> b) -> a -> b
$ \Object
object -> do
    Str
mutators <- forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"mutators"
    U32
joinableBy <- forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"joinable_by"
    U32
maxPlayers <- forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"max_players"
    Str
gameName <- forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"game_name"
    Str
password <- forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"password"
    Bool
flag <- forall value. FromJSON value => Object -> String -> Parser value
Json.required Object
object String
"flag"
    forall (f :: * -> *) a. Applicative f => a -> f a
pure
      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 =
    [(Key, Value)] -> Value
Json.object
      [ forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"mutators" forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> Str
mutators PrivateMatchSettings
x,
        forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"joinable_by" forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> U32
joinableBy PrivateMatchSettings
x,
        forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"max_players" forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> U32
maxPlayers PrivateMatchSettings
x,
        forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"game_name" forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> Str
gameName PrivateMatchSettings
x,
        forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"password" forall a b. (a -> b) -> a -> b
$ PrivateMatchSettings -> Str
password PrivateMatchSettings
x,
        forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"flag" 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" forall a b. (a -> b) -> a -> b
$
    [((Key, Value), Bool)] -> Value
Schema.object
      [ (forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"mutators" forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Str.schema, Bool
True),
        (forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"joinable_by" forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
U32.schema, Bool
True),
        (forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"max_players" forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
U32.schema, Bool
True),
        (forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"game_name" forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Str.schema, Bool
True),
        (forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"password" forall a b. (a -> b) -> a -> b
$ Schema -> Value
Schema.ref Schema
Str.schema, Bool
True),
        (forall value pair.
(ToJSON value, KeyValue pair) =>
String -> value -> pair
Json.pair String
"flag" 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)
    forall a. Semigroup a => a -> a -> a
<> U32 -> BitPut
U32.bitPut (PrivateMatchSettings -> U32
joinableBy PrivateMatchSettings
privateMatchSettingsAttribute)
    forall a. Semigroup a => a -> a -> a
<> U32 -> BitPut
U32.bitPut (PrivateMatchSettings -> U32
maxPlayers PrivateMatchSettings
privateMatchSettingsAttribute)
    forall a. Semigroup a => a -> a -> a
<> Str -> BitPut
Str.bitPut (PrivateMatchSettings -> Str
gameName PrivateMatchSettings
privateMatchSettingsAttribute)
    forall a. Semigroup a => a -> a -> a
<> Str -> BitPut
Str.bitPut (PrivateMatchSettings -> Str
password PrivateMatchSettings
privateMatchSettingsAttribute)
    forall a. Semigroup a => a -> a -> a
<> Bool -> BitPut
BitPut.bool (PrivateMatchSettings -> Bool
flag PrivateMatchSettings
privateMatchSettingsAttribute)

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