Skip to content

EVE SDE Schema

Documentation for third-party developers

sovereigntyUpgrades.jsonl

Schema

  • _key (required): integer
    Range: 81615 .. 82592
  • fuel_hourly_upkeep: integer
    Range: 25 .. 205
  • fuel_startup_cost: integer
    Range: 1770 .. 82600
  • fuel_type_id: integer
    Range: 81143 .. 81144
  • mutually_exclusive_group (required): string
  • power_allocation (required): integer
    Range: 200 .. 1750
  • workforce_allocation (required): integer
    Range: 1500 .. 18100

Code snippets

// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using QuickType;
//
//    var sovereigntyUpgrade = SovereigntyUpgrade.FromJson(jsonString);

namespace QuickType
{
    using System;
    using System.Collections.Generic;

    using System.Globalization;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public partial class SovereigntyUpgrade
    {
        [JsonProperty("_key")]
        public long Key { get; set; }

        [JsonProperty("fuel_hourly_upkeep", NullValueHandling = NullValueHandling.Ignore)]
        public long? FuelHourlyUpkeep { get; set; }

        [JsonProperty("fuel_startup_cost", NullValueHandling = NullValueHandling.Ignore)]
        public long? FuelStartupCost { get; set; }

        [JsonProperty("fuel_type_id", NullValueHandling = NullValueHandling.Ignore)]
        public long? FuelTypeId { get; set; }

        [JsonProperty("mutually_exclusive_group")]
        [JsonConverter(typeof(MinMaxLengthCheckConverter))]
        public string MutuallyExclusiveGroup { get; set; }

        [JsonProperty("power_allocation")]
        public long PowerAllocation { get; set; }

        [JsonProperty("workforce_allocation")]
        public long WorkforceAllocation { get; set; }
    }

    public partial class SovereigntyUpgrade
    {
        public static SovereigntyUpgrade FromJson(string json) => JsonConvert.DeserializeObject<SovereigntyUpgrade>(json, QuickType.Converter.Settings);
    }

    public static class Serialize
    {
        public static string ToJson(this SovereigntyUpgrade self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
    }

    internal static class Converter
    {
        public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
        {
            MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
            DateParseHandling = DateParseHandling.None,
            Converters =
            {
                new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
            },
        };
    }

    internal class MinMaxLengthCheckConverter : JsonConverter
    {
        public override bool CanConvert(Type t) => t == typeof(string);

        public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
        {
            var value = serializer.Deserialize<string>(reader);
            if (value.Length >= 5 && value.Length <= 16)
            {
                return value;
            }
            throw new Exception("Cannot unmarshal type string");
        }

        public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
        {
            var value = (string)untypedValue;
            if (value.Length >= 5 && value.Length <= 16)
            {
                serializer.Serialize(writer, value);
                return;
            }
            throw new Exception("Cannot marshal type string");
        }

        public static readonly MinMaxLengthCheckConverter Singleton = new MinMaxLengthCheckConverter();
    }
}
// Code generated from JSON Schema using quicktype. DO NOT EDIT.
// To parse and unparse this JSON data, add this code to your project and do:
//
//    sovereigntyUpgrade, err := UnmarshalSovereigntyUpgrade(bytes)
//    bytes, err = sovereigntyUpgrade.Marshal()

package model

import "encoding/json"

func UnmarshalSovereigntyUpgrade(data []byte) (SovereigntyUpgrade, error) {
    var r SovereigntyUpgrade
    err := json.Unmarshal(data, &r)
    return r, err
}

func (r *SovereigntyUpgrade) Marshal() ([]byte, error) {
    return json.Marshal(r)
}

type SovereigntyUpgrade struct {
    Key                    int64  `json:"_key"`
    FuelHourlyUpkeep       *int64 `json:"fuel_hourly_upkeep,omitempty"`
    FuelStartupCost        *int64 `json:"fuel_startup_cost,omitempty"`
    FuelTypeID             *int64 `json:"fuel_type_id,omitempty"`
    MutuallyExclusiveGroup string `json:"mutually_exclusive_group"`
    PowerAllocation        int64  `json:"power_allocation"`
    WorkforceAllocation    int64  `json:"workforce_allocation"`
}
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "_key": {
            "type": "integer",
            "minimum": 81615,
            "maximum": 82592
        },
        "fuel_hourly_upkeep": {
            "type": "integer",
            "minimum": 25,
            "maximum": 205
        },
        "fuel_startup_cost": {
            "type": "integer",
            "minimum": 1770,
            "maximum": 82600
        },
        "fuel_type_id": {
            "type": "integer",
            "minimum": 81143,
            "maximum": 81144
        },
        "mutually_exclusive_group": {
            "type": "string",
            "minLength": 5,
            "maxLength": 16
        },
        "power_allocation": {
            "type": "integer",
            "minimum": 200,
            "maximum": 1750
        },
        "workforce_allocation": {
            "type": "integer",
            "minimum": 1500,
            "maximum": 18100
        }
    },
    "required": [
        "_key",
        "mutually_exclusive_group",
        "power_allocation",
        "workforce_allocation"
    ]
}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json               = Json { allowStructuredMapKeys = true }
// val sovereigntyUpgrade = json.parse(SovereigntyUpgrade.serializer(), jsonString)

package model

import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*

@Serializable
data class SovereigntyUpgrade (
    @SerialName("_key")
    val key: Long,

    @SerialName("fuel_hourly_upkeep")
    val fuelHourlyUpkeep: Long? = null,

    @SerialName("fuel_startup_cost")
    val fuelStartupCost: Long? = null,

    @SerialName("fuel_type_id")
    val fuelTypeId: Long? = null,

    @SerialName("mutually_exclusive_group")
    val mutuallyExclusiveGroup: String,

    @SerialName("power_allocation")
    val powerAllocation: Long,

    @SerialName("workforce_allocation")
    val workforceAllocation: Long
)
<?php

// This is a autogenerated file:SovereigntyUpgrade

class SovereigntyUpgrade {
    private int $key; // json:_key Required
    private ?int $fuelHourlyUpkeep; // json:fuel_hourly_upkeep Optional
    private ?int $fuelStartupCost; // json:fuel_startup_cost Optional
    private ?int $fuelTypeId; // json:fuel_type_id Optional
    private string $mutuallyExclusiveGroup; // json:mutually_exclusive_group Required
    private int $powerAllocation; // json:power_allocation Required
    private int $workforceAllocation; // json:workforce_allocation Required

    /**
     * @param int $key
     * @param int|null $fuelHourlyUpkeep
     * @param int|null $fuelStartupCost
     * @param int|null $fuelTypeId
     * @param string $mutuallyExclusiveGroup
     * @param int $powerAllocation
     * @param int $workforceAllocation
     */
    public function __construct(int $key, ?int $fuelHourlyUpkeep, ?int $fuelStartupCost, ?int $fuelTypeId, string $mutuallyExclusiveGroup, int $powerAllocation, int $workforceAllocation) {
        $this->key = $key;
        $this->fuelHourlyUpkeep = $fuelHourlyUpkeep;
        $this->fuelStartupCost = $fuelStartupCost;
        $this->fuelTypeId = $fuelTypeId;
        $this->mutuallyExclusiveGroup = $mutuallyExclusiveGroup;
        $this->powerAllocation = $powerAllocation;
        $this->workforceAllocation = $workforceAllocation;
    }

    /**
     * @param int $value
     * @throws Exception
     * @return int
     */
    public static function fromKey(int $value): int {
        return $value; /*int*/
    }

    /**
     * @throws Exception
     * @return int
     */
    public function toKey(): int {
        if (SovereigntyUpgrade::validateKey($this->key))  {
            return $this->key; /*int*/
        }
        throw new Exception('never get to this SovereigntyUpgrade::key');
    }

    /**
     * @param int
     * @return bool
     * @throws Exception
     */
    public static function validateKey(int $value): bool {
        if (!is_integer($value)) {
            throw new Exception("Attribute Error:SovereigntyUpgrade::key");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return int
     */
    public function getKey(): int {
        if (SovereigntyUpgrade::validateKey($this->key))  {
            return $this->key;
        }
        throw new Exception('never get to getKey SovereigntyUpgrade::key');
    }

    /**
     * @return int
     */
    public static function sampleKey(): int {
        return 31; /*31:key*/
    }

    /**
     * @param ?int $value
     * @throws Exception
     * @return ?int
     */
    public static function fromFuelHourlyUpkeep(?int $value): ?int {
        if (!is_null($value)) {
            return $value; /*int*/
        } else {
            return null;
        }
    }

    /**
     * @throws Exception
     * @return ?int
     */
    public function toFuelHourlyUpkeep(): ?int {
        if (SovereigntyUpgrade::validateFuelHourlyUpkeep($this->fuelHourlyUpkeep))  {
            if (!is_null($this->fuelHourlyUpkeep)) {
                return $this->fuelHourlyUpkeep; /*int*/
            } else {
                return  null;
            }
        }
        throw new Exception('never get to this SovereigntyUpgrade::fuelHourlyUpkeep');
    }

    /**
     * @param int|null
     * @return bool
     * @throws Exception
     */
    public static function validateFuelHourlyUpkeep(?int $value): bool {
        if (!is_null($value)) {
            if (!is_integer($value)) {
                throw new Exception("Attribute Error:SovereigntyUpgrade::fuelHourlyUpkeep");
            }
        }
        return true;
    }

    /**
     * @throws Exception
     * @return ?int
     */
    public function getFuelHourlyUpkeep(): ?int {
        if (SovereigntyUpgrade::validateFuelHourlyUpkeep($this->fuelHourlyUpkeep))  {
            return $this->fuelHourlyUpkeep;
        }
        throw new Exception('never get to getFuelHourlyUpkeep SovereigntyUpgrade::fuelHourlyUpkeep');
    }

    /**
     * @return ?int
     */
    public static function sampleFuelHourlyUpkeep(): ?int {
        return 32; /*32:fuelHourlyUpkeep*/
    }

    /**
     * @param ?int $value
     * @throws Exception
     * @return ?int
     */
    public static function fromFuelStartupCost(?int $value): ?int {
        if (!is_null($value)) {
            return $value; /*int*/
        } else {
            return null;
        }
    }

    /**
     * @throws Exception
     * @return ?int
     */
    public function toFuelStartupCost(): ?int {
        if (SovereigntyUpgrade::validateFuelStartupCost($this->fuelStartupCost))  {
            if (!is_null($this->fuelStartupCost)) {
                return $this->fuelStartupCost; /*int*/
            } else {
                return  null;
            }
        }
        throw new Exception('never get to this SovereigntyUpgrade::fuelStartupCost');
    }

    /**
     * @param int|null
     * @return bool
     * @throws Exception
     */
    public static function validateFuelStartupCost(?int $value): bool {
        if (!is_null($value)) {
            if (!is_integer($value)) {
                throw new Exception("Attribute Error:SovereigntyUpgrade::fuelStartupCost");
            }
        }
        return true;
    }

    /**
     * @throws Exception
     * @return ?int
     */
    public function getFuelStartupCost(): ?int {
        if (SovereigntyUpgrade::validateFuelStartupCost($this->fuelStartupCost))  {
            return $this->fuelStartupCost;
        }
        throw new Exception('never get to getFuelStartupCost SovereigntyUpgrade::fuelStartupCost');
    }

    /**
     * @return ?int
     */
    public static function sampleFuelStartupCost(): ?int {
        return 33; /*33:fuelStartupCost*/
    }

    /**
     * @param ?int $value
     * @throws Exception
     * @return ?int
     */
    public static function fromFuelTypeId(?int $value): ?int {
        if (!is_null($value)) {
            return $value; /*int*/
        } else {
            return null;
        }
    }

    /**
     * @throws Exception
     * @return ?int
     */
    public function toFuelTypeId(): ?int {
        if (SovereigntyUpgrade::validateFuelTypeId($this->fuelTypeId))  {
            if (!is_null($this->fuelTypeId)) {
                return $this->fuelTypeId; /*int*/
            } else {
                return  null;
            }
        }
        throw new Exception('never get to this SovereigntyUpgrade::fuelTypeId');
    }

    /**
     * @param int|null
     * @return bool
     * @throws Exception
     */
    public static function validateFuelTypeId(?int $value): bool {
        if (!is_null($value)) {
            if (!is_integer($value)) {
                throw new Exception("Attribute Error:SovereigntyUpgrade::fuelTypeId");
            }
        }
        return true;
    }

    /**
     * @throws Exception
     * @return ?int
     */
    public function getFuelTypeId(): ?int {
        if (SovereigntyUpgrade::validateFuelTypeId($this->fuelTypeId))  {
            return $this->fuelTypeId;
        }
        throw new Exception('never get to getFuelTypeId SovereigntyUpgrade::fuelTypeId');
    }

    /**
     * @return ?int
     */
    public static function sampleFuelTypeId(): ?int {
        return 34; /*34:fuelTypeId*/
    }

    /**
     * @param string $value
     * @throws Exception
     * @return string
     */
    public static function fromMutuallyExclusiveGroup(string $value): string {
        return $value; /*string*/
    }

    /**
     * @throws Exception
     * @return string
     */
    public function toMutuallyExclusiveGroup(): string {
        if (SovereigntyUpgrade::validateMutuallyExclusiveGroup($this->mutuallyExclusiveGroup))  {
            return $this->mutuallyExclusiveGroup; /*string*/
        }
        throw new Exception('never get to this SovereigntyUpgrade::mutuallyExclusiveGroup');
    }

    /**
     * @param string
     * @return bool
     * @throws Exception
     */
    public static function validateMutuallyExclusiveGroup(string $value): bool {
        if (!is_string($value)) {
            throw new Exception("Attribute Error:SovereigntyUpgrade::mutuallyExclusiveGroup");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return string
     */
    public function getMutuallyExclusiveGroup(): string {
        if (SovereigntyUpgrade::validateMutuallyExclusiveGroup($this->mutuallyExclusiveGroup))  {
            return $this->mutuallyExclusiveGroup;
        }
        throw new Exception('never get to getMutuallyExclusiveGroup SovereigntyUpgrade::mutuallyExclusiveGroup');
    }

    /**
     * @return string
     */
    public static function sampleMutuallyExclusiveGroup(): string {
        return 'SovereigntyUpgrade::mutuallyExclusiveGroup::35'; /*35:mutuallyExclusiveGroup*/
    }

    /**
     * @param int $value
     * @throws Exception
     * @return int
     */
    public static function fromPowerAllocation(int $value): int {
        return $value; /*int*/
    }

    /**
     * @throws Exception
     * @return int
     */
    public function toPowerAllocation(): int {
        if (SovereigntyUpgrade::validatePowerAllocation($this->powerAllocation))  {
            return $this->powerAllocation; /*int*/
        }
        throw new Exception('never get to this SovereigntyUpgrade::powerAllocation');
    }

    /**
     * @param int
     * @return bool
     * @throws Exception
     */
    public static function validatePowerAllocation(int $value): bool {
        if (!is_integer($value)) {
            throw new Exception("Attribute Error:SovereigntyUpgrade::powerAllocation");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return int
     */
    public function getPowerAllocation(): int {
        if (SovereigntyUpgrade::validatePowerAllocation($this->powerAllocation))  {
            return $this->powerAllocation;
        }
        throw new Exception('never get to getPowerAllocation SovereigntyUpgrade::powerAllocation');
    }

    /**
     * @return int
     */
    public static function samplePowerAllocation(): int {
        return 36; /*36:powerAllocation*/
    }

    /**
     * @param int $value
     * @throws Exception
     * @return int
     */
    public static function fromWorkforceAllocation(int $value): int {
        return $value; /*int*/
    }

    /**
     * @throws Exception
     * @return int
     */
    public function toWorkforceAllocation(): int {
        if (SovereigntyUpgrade::validateWorkforceAllocation($this->workforceAllocation))  {
            return $this->workforceAllocation; /*int*/
        }
        throw new Exception('never get to this SovereigntyUpgrade::workforceAllocation');
    }

    /**
     * @param int
     * @return bool
     * @throws Exception
     */
    public static function validateWorkforceAllocation(int $value): bool {
        if (!is_integer($value)) {
            throw new Exception("Attribute Error:SovereigntyUpgrade::workforceAllocation");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return int
     */
    public function getWorkforceAllocation(): int {
        if (SovereigntyUpgrade::validateWorkforceAllocation($this->workforceAllocation))  {
            return $this->workforceAllocation;
        }
        throw new Exception('never get to getWorkforceAllocation SovereigntyUpgrade::workforceAllocation');
    }

    /**
     * @return int
     */
    public static function sampleWorkforceAllocation(): int {
        return 37; /*37:workforceAllocation*/
    }

    /**
     * @throws Exception
     * @return bool
     */
    public function validate(): bool {
        return SovereigntyUpgrade::validateKey($this->key)
        || SovereigntyUpgrade::validateFuelHourlyUpkeep($this->fuelHourlyUpkeep)
        || SovereigntyUpgrade::validateFuelStartupCost($this->fuelStartupCost)
        || SovereigntyUpgrade::validateFuelTypeId($this->fuelTypeId)
        || SovereigntyUpgrade::validateMutuallyExclusiveGroup($this->mutuallyExclusiveGroup)
        || SovereigntyUpgrade::validatePowerAllocation($this->powerAllocation)
        || SovereigntyUpgrade::validateWorkforceAllocation($this->workforceAllocation);
    }

    /**
     * @return stdClass
     * @throws Exception
     */
    public function to(): stdClass  {
        $out = new stdClass();
        $out->{'_key'} = $this->toKey();
        $out->{'fuel_hourly_upkeep'} = $this->toFuelHourlyUpkeep();
        $out->{'fuel_startup_cost'} = $this->toFuelStartupCost();
        $out->{'fuel_type_id'} = $this->toFuelTypeId();
        $out->{'mutually_exclusive_group'} = $this->toMutuallyExclusiveGroup();
        $out->{'power_allocation'} = $this->toPowerAllocation();
        $out->{'workforce_allocation'} = $this->toWorkforceAllocation();
        return $out;
    }

    /**
     * @param stdClass $obj
     * @return SovereigntyUpgrade
     * @throws Exception
     */
    public static function from(stdClass $obj): SovereigntyUpgrade {
        return new SovereigntyUpgrade(
         SovereigntyUpgrade::fromKey($obj->{'_key'})
        ,SovereigntyUpgrade::fromFuelHourlyUpkeep($obj->{'fuel_hourly_upkeep'})
        ,SovereigntyUpgrade::fromFuelStartupCost($obj->{'fuel_startup_cost'})
        ,SovereigntyUpgrade::fromFuelTypeId($obj->{'fuel_type_id'})
        ,SovereigntyUpgrade::fromMutuallyExclusiveGroup($obj->{'mutually_exclusive_group'})
        ,SovereigntyUpgrade::fromPowerAllocation($obj->{'power_allocation'})
        ,SovereigntyUpgrade::fromWorkforceAllocation($obj->{'workforce_allocation'})
        );
    }

    /**
     * @return SovereigntyUpgrade
     */
    public static function sample(): SovereigntyUpgrade {
        return new SovereigntyUpgrade(
         SovereigntyUpgrade::sampleKey()
        ,SovereigntyUpgrade::sampleFuelHourlyUpkeep()
        ,SovereigntyUpgrade::sampleFuelStartupCost()
        ,SovereigntyUpgrade::sampleFuelTypeId()
        ,SovereigntyUpgrade::sampleMutuallyExclusiveGroup()
        ,SovereigntyUpgrade::samplePowerAllocation()
        ,SovereigntyUpgrade::sampleWorkforceAllocation()
        );
    }
}
from typing import Optional, Any, TypeVar, Type, cast


T = TypeVar("T")


def from_int(x: Any) -> int:
    assert isinstance(x, int) and not isinstance(x, bool)
    return x


def from_none(x: Any) -> Any:
    assert x is None
    return x


def from_union(fs, x):
    for f in fs:
        try:
            return f(x)
        except:
            pass
    assert False


def from_str(x: Any) -> str:
    assert isinstance(x, str)
    return x


def to_class(c: Type[T], x: Any) -> dict:
    assert isinstance(x, c)
    return cast(Any, x).to_dict()


class SovereigntyUpgrade:
    key: int
    fuel_hourly_upkeep: Optional[int]
    fuel_startup_cost: Optional[int]
    fuel_type_id: Optional[int]
    mutually_exclusive_group: str
    power_allocation: int
    workforce_allocation: int

    def __init__(self, key: int, fuel_hourly_upkeep: Optional[int], fuel_startup_cost: Optional[int], fuel_type_id: Optional[int], mutually_exclusive_group: str, power_allocation: int, workforce_allocation: int) -> None:
        self.key = key
        self.fuel_hourly_upkeep = fuel_hourly_upkeep
        self.fuel_startup_cost = fuel_startup_cost
        self.fuel_type_id = fuel_type_id
        self.mutually_exclusive_group = mutually_exclusive_group
        self.power_allocation = power_allocation
        self.workforce_allocation = workforce_allocation

    @staticmethod
    def from_dict(obj: Any) -> 'SovereigntyUpgrade':
        assert isinstance(obj, dict)
        key = from_int(obj.get("_key"))
        fuel_hourly_upkeep = from_union([from_int, from_none], obj.get("fuel_hourly_upkeep"))
        fuel_startup_cost = from_union([from_int, from_none], obj.get("fuel_startup_cost"))
        fuel_type_id = from_union([from_int, from_none], obj.get("fuel_type_id"))
        mutually_exclusive_group = from_str(obj.get("mutually_exclusive_group"))
        power_allocation = from_int(obj.get("power_allocation"))
        workforce_allocation = from_int(obj.get("workforce_allocation"))
        return SovereigntyUpgrade(key, fuel_hourly_upkeep, fuel_startup_cost, fuel_type_id, mutually_exclusive_group, power_allocation, workforce_allocation)

    def to_dict(self) -> dict:
        result: dict = {}
        result["_key"] = from_int(self.key)
        if self.fuel_hourly_upkeep is not None:
            result["fuel_hourly_upkeep"] = from_union([from_int, from_none], self.fuel_hourly_upkeep)
        if self.fuel_startup_cost is not None:
            result["fuel_startup_cost"] = from_union([from_int, from_none], self.fuel_startup_cost)
        if self.fuel_type_id is not None:
            result["fuel_type_id"] = from_union([from_int, from_none], self.fuel_type_id)
        result["mutually_exclusive_group"] = from_str(self.mutually_exclusive_group)
        result["power_allocation"] = from_int(self.power_allocation)
        result["workforce_allocation"] = from_int(self.workforce_allocation)
        return result


def sovereignty_upgrade_from_dict(s: Any) -> SovereigntyUpgrade:
    return SovereigntyUpgrade.from_dict(s)


def sovereignty_upgrade_to_dict(x: SovereigntyUpgrade) -> Any:
    return to_class(SovereigntyUpgrade, x)
// To parse this data:
//
//   import { Convert, SovereigntyUpgrade } from "./file";
//
//   const sovereigntyUpgrade = Convert.toSovereigntyUpgrade(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.

export interface SovereigntyUpgrade {
    _key:                     number;
    fuel_hourly_upkeep?:      number;
    fuel_startup_cost?:       number;
    fuel_type_id?:            number;
    mutually_exclusive_group: string;
    power_allocation:         number;
    workforce_allocation:     number;
    [property: string]: any;
}

// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
    public static toSovereigntyUpgrade(json: string): SovereigntyUpgrade {
        return cast(JSON.parse(json), r("SovereigntyUpgrade"));
    }

    public static sovereigntyUpgradeToJson(value: SovereigntyUpgrade): string {
        return JSON.stringify(uncast(value, r("SovereigntyUpgrade")), null, 2);
    }
}

function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
    const prettyTyp = prettyTypeName(typ);
    const parentText = parent ? ` on ${parent}` : '';
    const keyText = key ? ` for key "${key}"` : '';
    throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
}

function prettyTypeName(typ: any): string {
    if (Array.isArray(typ)) {
        if (typ.length === 2 && typ[0] === undefined) {
            return `an optional ${prettyTypeName(typ[1])}`;
        } else {
            return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
        }
    } else if (typeof typ === "object" && typ.literal !== undefined) {
        return typ.literal;
    } else {
        return typeof typ;
    }
}

function jsonToJSProps(typ: any): any {
    if (typ.jsonToJS === undefined) {
        const map: any = {};
        typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
        typ.jsonToJS = map;
    }
    return typ.jsonToJS;
}

function jsToJSONProps(typ: any): any {
    if (typ.jsToJSON === undefined) {
        const map: any = {};
        typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
        typ.jsToJSON = map;
    }
    return typ.jsToJSON;
}

function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
    function transformPrimitive(typ: string, val: any): any {
        if (typeof typ === typeof val) return val;
        return invalidValue(typ, val, key, parent);
    }

    function transformUnion(typs: any[], val: any): any {
        // val must validate against one typ in typs
        const l = typs.length;
        for (let i = 0; i < l; i++) {
            const typ = typs[i];
            try {
                return transform(val, typ, getProps);
            } catch (_) {}
        }
        return invalidValue(typs, val, key, parent);
    }

    function transformEnum(cases: string[], val: any): any {
        if (cases.indexOf(val) !== -1) return val;
        return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
    }

    function transformArray(typ: any, val: any): any {
        // val must be an array with no invalid elements
        if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
        return val.map(el => transform(el, typ, getProps));
    }

    function transformDate(val: any): any {
        if (val === null) {
            return null;
        }
        const d = new Date(val);
        if (isNaN(d.valueOf())) {
            return invalidValue(l("Date"), val, key, parent);
        }
        return d;
    }

    function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
        if (val === null || typeof val !== "object" || Array.isArray(val)) {
            return invalidValue(l(ref || "object"), val, key, parent);
        }
        const result: any = {};
        Object.getOwnPropertyNames(props).forEach(key => {
            const prop = props[key];
            const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
            result[prop.key] = transform(v, prop.typ, getProps, key, ref);
        });
        Object.getOwnPropertyNames(val).forEach(key => {
            if (!Object.prototype.hasOwnProperty.call(props, key)) {
                result[key] = transform(val[key], additional, getProps, key, ref);
            }
        });
        return result;
    }

    if (typ === "any") return val;
    if (typ === null) {
        if (val === null) return val;
        return invalidValue(typ, val, key, parent);
    }
    if (typ === false) return invalidValue(typ, val, key, parent);
    let ref: any = undefined;
    while (typeof typ === "object" && typ.ref !== undefined) {
        ref = typ.ref;
        typ = typeMap[typ.ref];
    }
    if (Array.isArray(typ)) return transformEnum(typ, val);
    if (typeof typ === "object") {
        return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
            : typ.hasOwnProperty("arrayItems")    ? transformArray(typ.arrayItems, val)
            : typ.hasOwnProperty("props")         ? transformObject(getProps(typ), typ.additional, val)
            : invalidValue(typ, val, key, parent);
    }
    // Numbers can be parsed by Date but shouldn't be.
    if (typ === Date && typeof val !== "number") return transformDate(val);
    return transformPrimitive(typ, val);
}

function cast<T>(val: any, typ: any): T {
    return transform(val, typ, jsonToJSProps);
}

function uncast<T>(val: T, typ: any): any {
    return transform(val, typ, jsToJSONProps);
}

function l(typ: any) {
    return { literal: typ };
}

function a(typ: any) {
    return { arrayItems: typ };
}

function u(...typs: any[]) {
    return { unionMembers: typs };
}

function o(props: any[], additional: any) {
    return { props, additional };
}

function m(additional: any) {
    return { props: [], additional };
}

function r(name: string) {
    return { ref: name };
}

const typeMap: any = {
    "SovereigntyUpgrade": o([
        { json: "_key", js: "_key", typ: 0 },
        { json: "fuel_hourly_upkeep", js: "fuel_hourly_upkeep", typ: u(undefined, 0) },
        { json: "fuel_startup_cost", js: "fuel_startup_cost", typ: u(undefined, 0) },
        { json: "fuel_type_id", js: "fuel_type_id", typ: u(undefined, 0) },
        { json: "mutually_exclusive_group", js: "mutually_exclusive_group", typ: "" },
        { json: "power_allocation", js: "power_allocation", typ: 0 },
        { json: "workforce_allocation", js: "workforce_allocation", typ: 0 },
    ], "any"),
};