Skip to content

EVE SDE Schema

Documentation for third-party developers

expertSystems.jsonl

Schema

  • _key (required): integer
    Range: 57190 .. 95744
  • associatedShipTypes: array of integer
    Type: integer
    Range: 582 .. 91858
  • durationDays (required): integer
    Range: 1 .. 30
  • hidden (required): boolean
  • internalName (required): string
  • retired (required): boolean
  • skillsGranted (required): array of object
    • level (required): integer
      Range: 1 .. 5
    • typeID (required): integer
      Range: 2406 .. 90728

Code snippets

// <auto-generated />
//
// To parse this JSON data, add NuGet 'System.Text.Json' then do:
//
//    using QuickType;
//
//    var expertSystem = ExpertSystem.FromJson(jsonString);
#nullable enable
#pragma warning disable CS8618
#pragma warning disable CS8601
#pragma warning disable CS8602
#pragma warning disable CS8603

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

    using System.Text.Json;
    using System.Text.Json.Serialization;
    using System.Globalization;

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

        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        [JsonPropertyName("associatedShipTypes")]
        public long[]? AssociatedShipTypes { get; set; }

        [JsonPropertyName("durationDays")]
        public long DurationDays { get; set; }

        [JsonPropertyName("hidden")]
        public bool Hidden { get; set; }

        [JsonPropertyName("internalName")]
        [JsonConverter(typeof(MinMaxLengthCheckConverter))]
        public string InternalName { get; set; }

        [JsonPropertyName("retired")]
        public bool Retired { get; set; }

        [JsonPropertyName("skillsGranted")]
        public SkillsGranted[] SkillsGranted { get; set; }
    }

    public partial class SkillsGranted
    {
        [JsonPropertyName("level")]
        public long Level { get; set; }

        [JsonPropertyName("typeID")]
        public long TypeId { get; set; }
    }

    public partial class ExpertSystem
    {
        public static ExpertSystem FromJson(string json) => JsonSerializer.Deserialize<ExpertSystem>(json, QuickType.Converter.Settings);
    }

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

    internal static class Converter
    {
        public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
        {
            Converters =
            {
                new DateOnlyConverter(),
                new TimeOnlyConverter(),
                IsoDateTimeOffsetConverter.Singleton
            },
        };
    }

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

        public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            var value = reader.GetString();
            if (value.Length >= 9 && value.Length <= 41)
            {
                return value;
            }
            throw new Exception("Cannot unmarshal type string");
        }

        public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
        {
            if (value.Length >= 9 && value.Length <= 41)
            {
                JsonSerializer.Serialize(writer, value, options);
                return;
            }
            throw new Exception("Cannot marshal type string");
        }

        public static readonly MinMaxLengthCheckConverter Singleton = new MinMaxLengthCheckConverter();
    }

    public class DateOnlyConverter : JsonConverter<DateOnly>
    {
        private readonly string serializationFormat;
        public DateOnlyConverter() : this(null) { }

        public DateOnlyConverter(string? serializationFormat)
        {
                this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
        }

        public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
                var value = reader.GetString();
                return DateOnly.Parse(value!);
        }

        public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
                => writer.WriteStringValue(value.ToString(serializationFormat));
    }

    public class TimeOnlyConverter : JsonConverter<TimeOnly>
    {
        private readonly string serializationFormat;

        public TimeOnlyConverter() : this(null) { }

        public TimeOnlyConverter(string? serializationFormat)
        {
                this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
        }

        public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
                var value = reader.GetString();
                return TimeOnly.Parse(value!);
        }

        public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
                => writer.WriteStringValue(value.ToString(serializationFormat));
    }

    internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
    {
        public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);

        private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";

        private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
        private string? _dateTimeFormat;
        private CultureInfo? _culture;

        public DateTimeStyles DateTimeStyles
        {
                get => _dateTimeStyles;
                set => _dateTimeStyles = value;
        }

        public string? DateTimeFormat
        {
                get => _dateTimeFormat ?? string.Empty;
                set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
        }

        public CultureInfo Culture
        {
                get => _culture ?? CultureInfo.CurrentCulture;
                set => _culture = value;
        }

        public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
        {
                string text;


                if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
                        || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
                {
                        value = value.ToUniversalTime();
                }

                text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);

                writer.WriteStringValue(text);
        }

        public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
                string? dateText = reader.GetString();

                if (string.IsNullOrEmpty(dateText) == false)
                {
                        if (!string.IsNullOrEmpty(_dateTimeFormat))
                        {
                                return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
                        }
                        else
                        {
                                return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
                        }
                }
                else
                {
                        return default(DateTimeOffset);
                }
        }


        public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
    }
}
#pragma warning restore CS8618
#pragma warning restore CS8601
#pragma warning restore CS8602
#pragma warning restore CS8603
// 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:
//
//    expertSystem, err := UnmarshalExpertSystem(bytes)
//    bytes, err = expertSystem.Marshal()

package model

import "encoding/json"

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

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

type ExpertSystem struct {
    Key                 int64           `json:"_key"`
    AssociatedShipTypes []int64         `json:"associatedShipTypes,omitempty"`
    DurationDays        int64           `json:"durationDays"`
    Hidden              bool            `json:"hidden"`
    InternalName        string          `json:"internalName"`
    Retired             bool            `json:"retired"`
    SkillsGranted       []SkillsGranted `json:"skillsGranted"`
}

type SkillsGranted struct {
    Level  int64 `json:"level"`
    TypeID int64 `json:"typeID"`
}
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"_key":{"type":"integer","minimum":57190,"maximum":95744},"associatedShipTypes":{"type":"array","items":{"type":"integer","minimum":582,"maximum":91858},"minItems":1,"maxItems":30},"durationDays":{"type":"integer","minimum":1,"maximum":30},"hidden":{"type":"boolean"},"internalName":{"type":"string","minLength":9,"maxLength":41},"retired":{"type":"boolean"},"skillsGranted":{"type":"array","items":{"type":"object","properties":{"level":{"type":"integer","minimum":1,"maximum":5},"typeID":{"type":"integer","minimum":2406,"maximum":90728}},"required":["level","typeID"]},"minItems":1,"maxItems":289}},"required":["_key","durationDays","hidden","internalName","retired","skillsGranted"]}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json         = Json { allowStructuredMapKeys = true }
// val expertSystem = json.parse(ExpertSystem.serializer(), jsonString)

package model

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

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

    val associatedShipTypes: List<Long>? = null,
    val durationDays: Long,
    val hidden: Boolean,
    val internalName: String,
    val retired: Boolean,
    val skillsGranted: List<SkillsGranted>
)

@Serializable
data class SkillsGranted (
    val level: Long,

    @SerialName("typeID")
    val typeId: Long
)
<?php

// This is an autogenerated file:ExpertSystem

class ExpertSystem {
    private int $key; // json:_key Required
    private ?array $associatedShipTypes; // json:associatedShipTypes Optional
    private int $durationDays; // json:durationDays Required
    private bool $hidden; // json:hidden Required
    private string $internalName; // json:internalName Required
    private bool $retired; // json:retired Required
    private array $skillsGranted; // json:skillsGranted Required

    /**
     * @param int $key
     * @param array|null $associatedShipTypes
     * @param int $durationDays
     * @param bool $hidden
     * @param string $internalName
     * @param bool $retired
     * @param array $skillsGranted
     */
    public function __construct(int $key, ?array $associatedShipTypes, int $durationDays, bool $hidden, string $internalName, bool $retired, array $skillsGranted) {
        $this->key = $key;
        $this->associatedShipTypes = $associatedShipTypes;
        $this->durationDays = $durationDays;
        $this->hidden = $hidden;
        $this->internalName = $internalName;
        $this->retired = $retired;
        $this->skillsGranted = $skillsGranted;
    }

    /**
     * @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 (ExpertSystem::validateKey($this->key))  {
            return $this->key; /*int*/
        }
        throw new Exception('never get to this ExpertSystem::key');
    }

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

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

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

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

    /**
     * @throws Exception
     * @return ?array
     */
    public function toAssociatedShipTypes(): ?array {
        if (ExpertSystem::validateAssociatedShipTypes($this->associatedShipTypes))  {
            if (!is_null($this->associatedShipTypes)) {
                return array_map(function ($value) {
                    return $value; /*int*/
                }, $this->associatedShipTypes);
            } else {
                return  null;
            }
        }
        throw new Exception('never get to this ExpertSystem::associatedShipTypes');
    }

    /**
     * @param array|null
     * @return bool
     * @throws Exception
     */
    public static function validateAssociatedShipTypes(?array $value): bool {
        if (!is_null($value)) {
            if (!is_array($value)) {
                throw new Exception("Attribute Error:ExpertSystem::associatedShipTypes");
            }
            array_walk($value, function($value_v) {
                if (!is_integer($value_v)) {
                    throw new Exception("Attribute Error:ExpertSystem::associatedShipTypes");
                }
            });
        }
        return true;
    }

    /**
     * @throws Exception
     * @return ?array
     */
    public function getAssociatedShipTypes(): ?array {
        if (ExpertSystem::validateAssociatedShipTypes($this->associatedShipTypes))  {
            return $this->associatedShipTypes;
        }
        throw new Exception('never get to getAssociatedShipTypes ExpertSystem::associatedShipTypes');
    }

    /**
     * @return ?array
     */
    public static function sampleAssociatedShipTypes(): ?array {
        return  array(
            32 /*32:*/
        ); /* 32:associatedShipTypes*/
    }

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

    /**
     * @throws Exception
     * @return int
     */
    public function toDurationDays(): int {
        if (ExpertSystem::validateDurationDays($this->durationDays))  {
            return $this->durationDays; /*int*/
        }
        throw new Exception('never get to this ExpertSystem::durationDays');
    }

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

    /**
     * @throws Exception
     * @return int
     */
    public function getDurationDays(): int {
        if (ExpertSystem::validateDurationDays($this->durationDays))  {
            return $this->durationDays;
        }
        throw new Exception('never get to getDurationDays ExpertSystem::durationDays');
    }

    /**
     * @return int
     */
    public static function sampleDurationDays(): int {
        return 33; /*33:durationDays*/
    }

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

    /**
     * @throws Exception
     * @return bool
     */
    public function toHidden(): bool {
        if (ExpertSystem::validateHidden($this->hidden))  {
            return $this->hidden; /*bool*/
        }
        throw new Exception('never get to this ExpertSystem::hidden');
    }

    /**
     * @param bool
     * @return bool
     * @throws Exception
     */
    public static function validateHidden(bool $value): bool {
        if (!is_bool($value)) {
            throw new Exception("Attribute Error:ExpertSystem::hidden");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return bool
     */
    public function getHidden(): bool {
        if (ExpertSystem::validateHidden($this->hidden))  {
            return $this->hidden;
        }
        throw new Exception('never get to getHidden ExpertSystem::hidden');
    }

    /**
     * @return bool
     */
    public static function sampleHidden(): bool {
        return true; /*34:hidden*/
    }

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

    /**
     * @throws Exception
     * @return string
     */
    public function toInternalName(): string {
        if (ExpertSystem::validateInternalName($this->internalName))  {
            return $this->internalName; /*string*/
        }
        throw new Exception('never get to this ExpertSystem::internalName');
    }

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

    /**
     * @throws Exception
     * @return string
     */
    public function getInternalName(): string {
        if (ExpertSystem::validateInternalName($this->internalName))  {
            return $this->internalName;
        }
        throw new Exception('never get to getInternalName ExpertSystem::internalName');
    }

    /**
     * @return string
     */
    public static function sampleInternalName(): string {
        return 'ExpertSystem::internalName::35'; /*35:internalName*/
    }

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

    /**
     * @throws Exception
     * @return bool
     */
    public function toRetired(): bool {
        if (ExpertSystem::validateRetired($this->retired))  {
            return $this->retired; /*bool*/
        }
        throw new Exception('never get to this ExpertSystem::retired');
    }

    /**
     * @param bool
     * @return bool
     * @throws Exception
     */
    public static function validateRetired(bool $value): bool {
        if (!is_bool($value)) {
            throw new Exception("Attribute Error:ExpertSystem::retired");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return bool
     */
    public function getRetired(): bool {
        if (ExpertSystem::validateRetired($this->retired))  {
            return $this->retired;
        }
        throw new Exception('never get to getRetired ExpertSystem::retired');
    }

    /**
     * @return bool
     */
    public static function sampleRetired(): bool {
        return true; /*36:retired*/
    }

    /**
     * @param array $value
     * @throws Exception
     * @return array
     */
    public static function fromSkillsGranted(array $value): array {
        return  array_map(function ($value) {
            return SkillsGranted::from($value); /*class*/
        }, $value);
    }

    /**
     * @throws Exception
     * @return array
     */
    public function toSkillsGranted(): array {
        if (ExpertSystem::validateSkillsGranted($this->skillsGranted))  {
            return array_map(function ($value) {
                return $value->to(); /*class*/
            }, $this->skillsGranted);
        }
        throw new Exception('never get to this ExpertSystem::skillsGranted');
    }

    /**
     * @param array
     * @return bool
     * @throws Exception
     */
    public static function validateSkillsGranted(array $value): bool {
        if (!is_array($value)) {
            throw new Exception("Attribute Error:ExpertSystem::skillsGranted");
        }
        array_walk($value, function($value_v) {
            $value_v->validate();
        });
        return true;
    }

    /**
     * @throws Exception
     * @return array
     */
    public function getSkillsGranted(): array {
        if (ExpertSystem::validateSkillsGranted($this->skillsGranted))  {
            return $this->skillsGranted;
        }
        throw new Exception('never get to getSkillsGranted ExpertSystem::skillsGranted');
    }

    /**
     * @return array
     */
    public static function sampleSkillsGranted(): array {
        return  array(
            SkillsGranted::sample() /*37:*/
        ); /* 37:skillsGranted*/
    }

    /**
     * @throws Exception
     * @return bool
     */
    public function validate(): bool {
        return ExpertSystem::validateKey($this->key)
        || ExpertSystem::validateAssociatedShipTypes($this->associatedShipTypes)
        || ExpertSystem::validateDurationDays($this->durationDays)
        || ExpertSystem::validateHidden($this->hidden)
        || ExpertSystem::validateInternalName($this->internalName)
        || ExpertSystem::validateRetired($this->retired)
        || ExpertSystem::validateSkillsGranted($this->skillsGranted);
    }

    /**
     * @return stdClass
     * @throws Exception
     */
    public function to(): stdClass  {
        $out = new stdClass();
        $out->{'_key'} = $this->toKey();
        $out->{'associatedShipTypes'} = $this->toAssociatedShipTypes();
        $out->{'durationDays'} = $this->toDurationDays();
        $out->{'hidden'} = $this->toHidden();
        $out->{'internalName'} = $this->toInternalName();
        $out->{'retired'} = $this->toRetired();
        $out->{'skillsGranted'} = $this->toSkillsGranted();
        return $out;
    }

    /**
     * @param stdClass $obj
     * @return ExpertSystem
     * @throws Exception
     */
    public static function from(stdClass $obj): ExpertSystem {
        return new ExpertSystem(
         ExpertSystem::fromKey($obj->{'_key'})
        ,ExpertSystem::fromAssociatedShipTypes($obj->{'associatedShipTypes'})
        ,ExpertSystem::fromDurationDays($obj->{'durationDays'})
        ,ExpertSystem::fromHidden($obj->{'hidden'})
        ,ExpertSystem::fromInternalName($obj->{'internalName'})
        ,ExpertSystem::fromRetired($obj->{'retired'})
        ,ExpertSystem::fromSkillsGranted($obj->{'skillsGranted'})
        );
    }

    /**
     * @return ExpertSystem
     */
    public static function sample(): ExpertSystem {
        return new ExpertSystem(
         ExpertSystem::sampleKey()
        ,ExpertSystem::sampleAssociatedShipTypes()
        ,ExpertSystem::sampleDurationDays()
        ,ExpertSystem::sampleHidden()
        ,ExpertSystem::sampleInternalName()
        ,ExpertSystem::sampleRetired()
        ,ExpertSystem::sampleSkillsGranted()
        );
    }
}

// This is an autogenerated file:SkillsGranted

class SkillsGranted {
    private int $level; // json:level Required
    private int $typeId; // json:typeID Required

    /**
     * @param int $level
     * @param int $typeId
     */
    public function __construct(int $level, int $typeId) {
        $this->level = $level;
        $this->typeId = $typeId;
    }

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

    /**
     * @throws Exception
     * @return int
     */
    public function toLevel(): int {
        if (SkillsGranted::validateLevel($this->level))  {
            return $this->level; /*int*/
        }
        throw new Exception('never get to this SkillsGranted::level');
    }

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

    /**
     * @throws Exception
     * @return int
     */
    public function getLevel(): int {
        if (SkillsGranted::validateLevel($this->level))  {
            return $this->level;
        }
        throw new Exception('never get to getLevel SkillsGranted::level');
    }

    /**
     * @return int
     */
    public static function sampleLevel(): int {
        return 31; /*31:level*/
    }

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

    /**
     * @throws Exception
     * @return int
     */
    public function toTypeId(): int {
        if (SkillsGranted::validateTypeId($this->typeId))  {
            return $this->typeId; /*int*/
        }
        throw new Exception('never get to this SkillsGranted::typeId');
    }

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

    /**
     * @throws Exception
     * @return int
     */
    public function getTypeId(): int {
        if (SkillsGranted::validateTypeId($this->typeId))  {
            return $this->typeId;
        }
        throw new Exception('never get to getTypeId SkillsGranted::typeId');
    }

    /**
     * @return int
     */
    public static function sampleTypeId(): int {
        return 32; /*32:typeId*/
    }

    /**
     * @throws Exception
     * @return bool
     */
    public function validate(): bool {
        return SkillsGranted::validateLevel($this->level)
        || SkillsGranted::validateTypeId($this->typeId);
    }

    /**
     * @return stdClass
     * @throws Exception
     */
    public function to(): stdClass  {
        $out = new stdClass();
        $out->{'level'} = $this->toLevel();
        $out->{'typeID'} = $this->toTypeId();
        return $out;
    }

    /**
     * @param stdClass $obj
     * @return SkillsGranted
     * @throws Exception
     */
    public static function from(stdClass $obj): SkillsGranted {
        return new SkillsGranted(
         SkillsGranted::fromLevel($obj->{'level'})
        ,SkillsGranted::fromTypeId($obj->{'typeID'})
        );
    }

    /**
     * @return SkillsGranted
     */
    public static function sample(): SkillsGranted {
        return new SkillsGranted(
         SkillsGranted::sampleLevel()
        ,SkillsGranted::sampleTypeId()
        );
    }
}
from dataclasses import dataclass
from typing import Any, TypeVar, Callable, Type, cast


T = TypeVar("T")


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


def from_bool(x: Any) -> bool:
    assert isinstance(x, bool)
    return x


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


def from_list(f: Callable[[Any], T], x: Any) -> list[T]:
    assert isinstance(x, list)
    return [f(y) for y in 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 to_class(c: Type[T], x: Any) -> dict:
    assert isinstance(x, c)
    return cast(Any, x).to_dict()


@dataclass
class SkillsGranted:
    level: int
    type_id: int

    @staticmethod
    def from_dict(obj: Any) -> 'SkillsGranted':
        assert isinstance(obj, dict)
        level = from_int(obj.get("level"))
        type_id = from_int(obj.get("typeID"))
        return SkillsGranted(level, type_id)

    def to_dict(self) -> dict:
        result: dict = {}
        result["level"] = from_int(self.level)
        result["typeID"] = from_int(self.type_id)
        return result


@dataclass
class ExpertSystem:
    key: int
    duration_days: int
    hidden: bool
    internal_name: str
    retired: bool
    skills_granted: list[SkillsGranted]
    associated_ship_types: list[int] | None = None

    @staticmethod
    def from_dict(obj: Any) -> 'ExpertSystem':
        assert isinstance(obj, dict)
        key = from_int(obj.get("_key"))
        duration_days = from_int(obj.get("durationDays"))
        hidden = from_bool(obj.get("hidden"))
        internal_name = from_str(obj.get("internalName"))
        retired = from_bool(obj.get("retired"))
        skills_granted = from_list(SkillsGranted.from_dict, obj.get("skillsGranted"))
        associated_ship_types = from_union([lambda x: from_list(from_int, x), from_none], obj.get("associatedShipTypes"))
        return ExpertSystem(key, duration_days, hidden, internal_name, retired, skills_granted, associated_ship_types)

    def to_dict(self) -> dict:
        result: dict = {}
        result["_key"] = from_int(self.key)
        result["durationDays"] = from_int(self.duration_days)
        result["hidden"] = from_bool(self.hidden)
        result["internalName"] = from_str(self.internal_name)
        result["retired"] = from_bool(self.retired)
        result["skillsGranted"] = from_list(lambda x: to_class(SkillsGranted, x), self.skills_granted)
        if self.associated_ship_types is not None:
            result["associatedShipTypes"] = from_union([lambda x: from_list(from_int, x), from_none], self.associated_ship_types)
        return result


def expert_system_from_dict(s: Any) -> ExpertSystem:
    return ExpertSystem.from_dict(s)


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

export interface ExpertSystem {
    _key:                 number;
    associatedShipTypes?: [number, ...number[]];
    durationDays:         number;
    hidden:               boolean;
    internalName:         string;
    retired:              boolean;
    skillsGranted:        [SkillsGranted, ...SkillsGranted[]];
    [property: string]: unknown;
}

export interface SkillsGranted {
    level:  number;
    typeID: number;
    [property: string]: unknown;
}

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

    public static expertSystemToJson(value: ExpertSystem): string {
        return JSON.stringify(uncast(value, r("ExpertSystem")), 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 = {
    "ExpertSystem": o([
        { json: "_key", js: "_key", typ: 0 },
        { json: "associatedShipTypes", js: "associatedShipTypes", typ: u(undefined, a(0)) },
        { json: "durationDays", js: "durationDays", typ: 0 },
        { json: "hidden", js: "hidden", typ: true },
        { json: "internalName", js: "internalName", typ: "" },
        { json: "retired", js: "retired", typ: true },
        { json: "skillsGranted", js: "skillsGranted", typ: a(r("SkillsGranted")) },
    ], "any"),
    "SkillsGranted": o([
        { json: "level", js: "level", typ: 0 },
        { json: "typeID", js: "typeID", typ: 0 },
    ], "any"),
};