// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';

var Curry = require("bs-platform/lib/js/curry.js");
var Json_decode = require("@glennsl/bs-json/src/Json_decode.bs.js");
var Int$OptolithClient = require("../../Data/Int.bs.js");
var IntMap$OptolithClient = require("../../Data/IntMap.bs.js");
var Yaml_Zip$OptolithClient = require("../Utilities/Yaml_Zip.bs.js");
var JsonStrict$OptolithClient = require("../Utilities/JsonStrict.bs.js");
var GenericHelpers$OptolithClient = require("../Utilities/GenericHelpers.bs.js");
var Static_Erratum$OptolithClient = require("./Static_Erratum.bs.js");
var Static_Advantage$OptolithClient = require("./Static_Advantage.bs.js");
var Static_SourceRef$OptolithClient = require("./Static_SourceRef.bs.js");
var Static_SelectOption$OptolithClient = require("./Static_SelectOption.bs.js");
var Static_Prerequisites$OptolithClient = require("./Static_Prerequisites.bs.js");

function tL10n(json) {
  return {
          id: Json_decode.field("id", Json_decode.$$int, json),
          name: Json_decode.field("name", Json_decode.string, json),
          nameInWiki: JsonStrict$OptolithClient.optionalField("nameInWiki", Json_decode.string, json),
          rules: JsonStrict$OptolithClient.optionalField("rules", Json_decode.string, json),
          effect: JsonStrict$OptolithClient.optionalField("effect", Json_decode.string, json),
          selectOptions: JsonStrict$OptolithClient.optionalField("selectOptions", (function (param) {
                  return Json_decode.list(Static_SelectOption$OptolithClient.Decode.tL10n, param);
                }), json),
          input: JsonStrict$OptolithClient.optionalField("input", Json_decode.string, json),
          penalty: JsonStrict$OptolithClient.optionalField("penalty", Json_decode.string, json),
          combatTechniques: JsonStrict$OptolithClient.optionalField("combatTechniques", Json_decode.string, json),
          aeCost: JsonStrict$OptolithClient.optionalField("aeCost", Json_decode.string, json),
          protectiveCircle: JsonStrict$OptolithClient.optionalField("protectiveCircle", Json_decode.string, json),
          wardingCircle: JsonStrict$OptolithClient.optionalField("wardingCircle", Json_decode.string, json),
          volume: JsonStrict$OptolithClient.optionalField("volume", Json_decode.string, json),
          bindingCost: JsonStrict$OptolithClient.optionalField("bindingCost", Json_decode.string, json),
          property: JsonStrict$OptolithClient.optionalField("property", Json_decode.string, json),
          prerequisites: JsonStrict$OptolithClient.optionalField("prerequisites", Json_decode.string, json),
          prerequisitesIndex: JsonStrict$OptolithClient.optionalField("prerequisitesIndex", Static_Prerequisites$OptolithClient.Decode.tIndexWithLevelL10n, json),
          prerequisitesStart: JsonStrict$OptolithClient.optionalField("prerequisitesStart", Json_decode.string, json),
          prerequisitesEnd: JsonStrict$OptolithClient.optionalField("prerequisitesEnd", Json_decode.string, json),
          apValue: JsonStrict$OptolithClient.optionalField("apValue", Json_decode.string, json),
          apValueAppend: JsonStrict$OptolithClient.optionalField("apValueAppend", Json_decode.string, json),
          src: Json_decode.field("src", Static_SourceRef$OptolithClient.Decode.list, json),
          errata: Json_decode.field("errata", Static_Erratum$OptolithClient.Decode.list, json)
        };
}

var cost = Static_Advantage$OptolithClient.Decode.cost;

function partial_arg_0(json) {
  return /* List */{
          _0: Json_decode.list(Json_decode.$$int, json)
        };
}

var partial_arg_1 = {
  hd: (function (json) {
      var x = Json_decode.$$int(json);
      var switcher = x - 1 | 0;
      if (switcher > 4 || switcher < 0) {
        throw {
              RE_EXN_ID: Json_decode.DecodeError,
              _1: "Unknown combat technique category: " + Int$OptolithClient.show(x),
              Error: new Error()
            };
      }
      return switcher;
    }),
  tl: /* [] */0
};

var partial_arg = {
  hd: partial_arg_0,
  tl: partial_arg_1
};

function combatTechniques(param) {
  return Json_decode.oneOf(partial_arg, param);
}

function tUniv(json) {
  var partial_arg = GenericHelpers$OptolithClient.Decode.oneOrMany(Json_decode.$$int);
  return {
          id: Json_decode.field("id", Json_decode.$$int, json),
          cost: JsonStrict$OptolithClient.optionalField("cost", cost, json),
          levels: JsonStrict$OptolithClient.optionalField("levels", Json_decode.$$int, json),
          max: JsonStrict$OptolithClient.optionalField("max", Json_decode.$$int, json),
          selectOptionCategories: JsonStrict$OptolithClient.optionalField("selectOptionCategories", (function (param) {
                  return Json_decode.list(Static_SelectOption$OptolithClient.Decode.categoryWithGroups, param);
                }), json),
          selectOptions: JsonStrict$OptolithClient.optionalField("selectOptions", (function (param) {
                  return Json_decode.list(Static_SelectOption$OptolithClient.Decode.tUniv, param);
                }), json),
          extended: JsonStrict$OptolithClient.optionalField("extended", (function (param) {
                  return Json_decode.list(partial_arg, param);
                }), json),
          combatTechniques: JsonStrict$OptolithClient.optionalField("combatTechniques", combatTechniques, json),
          property: JsonStrict$OptolithClient.optionalField("property", Json_decode.$$int, json),
          aspect: JsonStrict$OptolithClient.optionalField("aspect", Json_decode.$$int, json),
          brew: JsonStrict$OptolithClient.optionalField("brew", Json_decode.$$int, json),
          prerequisites: Static_Prerequisites$OptolithClient.Decode.tWithLevel(json),
          prerequisitesIndex: JsonStrict$OptolithClient.optionalField("prerequisitesIndex", Static_Prerequisites$OptolithClient.Decode.tIndexWithLevelUniv, json),
          gr: Json_decode.field("gr", Json_decode.$$int, json),
          subgr: JsonStrict$OptolithClient.optionalField("subgr", Json_decode.$$int, json)
        };
}

function t(blessings, cantrips, combatTechniques, liturgicalChants, skills, spells, univ, l10n) {
  return [
          univ.id,
          {
            id: univ.id,
            name: l10n.name,
            nameInWiki: l10n.nameInWiki,
            levels: univ.levels,
            max: univ.max,
            rules: l10n.rules,
            effect: l10n.effect,
            selectOptions: Static_SelectOption$OptolithClient.Decode.mergeSelectOptions(l10n.selectOptions, univ.selectOptions, Static_SelectOption$OptolithClient.Decode.resolveCategories(blessings, cantrips, combatTechniques, liturgicalChants, skills, spells, univ.selectOptionCategories)),
            input: l10n.input,
            penalty: l10n.penalty,
            combatTechniques: univ.combatTechniques,
            combatTechniquesText: l10n.combatTechniques,
            aeCost: l10n.aeCost,
            protectiveCircle: l10n.protectiveCircle,
            wardingCircle: l10n.wardingCircle,
            volume: l10n.volume,
            bindingCost: l10n.bindingCost,
            property: univ.property,
            propertyText: l10n.property,
            aspect: univ.aspect,
            brew: univ.brew,
            extended: univ.extended,
            prerequisites: univ.prerequisites,
            prerequisitesText: l10n.prerequisites,
            prerequisitesTextIndex: Static_Prerequisites$OptolithClient.Decode.tIndexWithLevel(univ.prerequisitesIndex, l10n.prerequisitesIndex),
            prerequisitesTextStart: l10n.prerequisitesStart,
            prerequisitesTextEnd: l10n.prerequisitesEnd,
            apValue: univ.cost,
            apValueText: l10n.apValue,
            apValueTextAppend: l10n.apValueAppend,
            gr: univ.gr,
            subgr: univ.subgr,
            src: l10n.src,
            errata: l10n.errata
          }
        ];
}

function all(blessings, cantrips, combatTechniques, liturgicalChants, skills, spells, yamlData) {
  return Curry._1(IntMap$OptolithClient.fromList, Yaml_Zip$OptolithClient.zipBy(Int$OptolithClient.show, (function (param, param$1) {
                    return t(blessings, cantrips, combatTechniques, liturgicalChants, skills, spells, param, param$1);
                  }), (function (x) {
                    return x.id;
                  }), (function (x) {
                    return x.id;
                  }), Json_decode.list(tUniv, yamlData.specialAbilitiesUniv), Json_decode.list(tL10n, yamlData.specialAbilitiesL10n)));
}

var Decode = {
  tL10n: tL10n,
  cost: cost,
  combatTechniques: combatTechniques,
  tUniv: tUniv,
  t: t,
  all: all
};

exports.Decode = Decode;
/* IntMap-OptolithClient Not a pure module */
