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

var Curry = require("bs-platform/lib/js/curry.js");
var Pervasives = require("bs-platform/lib/js/pervasives.js");
var Json_decode = require("@glennsl/bs-json/src/Json_decode.bs.js");
var IC$OptolithClient = require("../Utilities/IC.bs.js");
var Int$OptolithClient = require("../../Data/Int.bs.js");
var ListH$OptolithClient = require("../../Data/ListH.bs.js");
var Maybe$OptolithClient = require("../../Data/Maybe.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 Static_Erratum$OptolithClient = require("./Static_Erratum.bs.js");
var Static_SourceRef$OptolithClient = require("./Static_SourceRef.bs.js");
var Static_Prerequisites$OptolithClient = require("./Static_Prerequisites.bs.js");

function applicationL10n(json) {
  return [
          Json_decode.field("id", Json_decode.$$int, json),
          Json_decode.field("name", Json_decode.string, json)
        ];
}

function useL10n(json) {
  return [
          Json_decode.field("id", Json_decode.$$int, json),
          Json_decode.field("name", Json_decode.string, json)
        ];
}

function tL10n(json) {
  return {
          id: Json_decode.field("id", Json_decode.$$int, json),
          name: Json_decode.field("name", Json_decode.string, json),
          applications: Json_decode.field("applications", (function (param) {
                  return Json_decode.list(applicationL10n, param);
                }), json),
          applicationsInput: JsonStrict$OptolithClient.optionalField("applicationsInput", Json_decode.string, json),
          uses: JsonStrict$OptolithClient.optionalField("uses", (function (param) {
                  return Json_decode.list(useL10n, param);
                }), json),
          encDescription: JsonStrict$OptolithClient.optionalField("encDescription", Json_decode.string, json),
          tools: JsonStrict$OptolithClient.optionalField("tools", Json_decode.string, json),
          quality: Json_decode.field("quality", Json_decode.string, json),
          failed: Json_decode.field("failed", Json_decode.string, json),
          critical: Json_decode.field("critical", Json_decode.string, json),
          botch: Json_decode.field("botch", 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)
        };
}

function applicationUniv(json) {
  return [
          Json_decode.field("id", Json_decode.$$int, json),
          Json_decode.field("prerequisite", Static_Prerequisites$OptolithClient.Decode.activatable, json)
        ];
}

function useUniv(json) {
  return [
          Json_decode.field("id", Json_decode.$$int, json),
          Json_decode.field("prerequisite", Static_Prerequisites$OptolithClient.Decode.activatable, json)
        ];
}

function encumbranceUniv(json) {
  var str = Json_decode.string(json);
  switch (str) {
    case "false" :
        Json_decode.$$int(json);
        return /* False */1;
    case "maybe" :
        Json_decode.$$int(json);
        return /* Maybe */2;
    case "true" :
        Json_decode.$$int(json);
        return /* True */0;
    default:
      throw {
            RE_EXN_ID: Json_decode.DecodeError,
            _1: "Unknown encumbrance: " + str,
            Error: new Error()
          };
  }
}

function tUniv(json) {
  return {
          id: Json_decode.field("id", Json_decode.$$int, json),
          applications: JsonStrict$OptolithClient.optionalField("applications", (function (param) {
                  return Json_decode.list(applicationUniv, param);
                }), json),
          uses: JsonStrict$OptolithClient.optionalField("uses", (function (param) {
                  return Json_decode.list(useUniv, param);
                }), json),
          check1: Json_decode.field("check1", Json_decode.$$int, json),
          check2: Json_decode.field("check2", Json_decode.$$int, json),
          check3: Json_decode.field("check3", Json_decode.$$int, json),
          ic: Json_decode.field("ic", IC$OptolithClient.Decode.t, json),
          enc: Json_decode.field("enc", encumbranceUniv, json),
          gr: Json_decode.field("gr", Json_decode.$$int, json)
        };
}

function newApplication(univ, l10n) {
  return [
          univ[0],
          {
            id: univ[0],
            name: l10n[1],
            prerequisite: /* Just */{
              _0: univ[1]
            }
          }
        ];
}

function application(l10n) {
  return [
          l10n[0],
          {
            id: l10n[0],
            name: l10n[1],
            prerequisite: /* Nothing */0
          }
        ];
}

function use(univ, l10n) {
  return [
          univ[0],
          {
            id: univ[0],
            name: l10n[1],
            prerequisite: univ[1]
          }
        ];
}

function t(univ, l10n) {
  var match = univ.enc;
  var tmp;
  switch (match) {
    case /* True */0 :
        tmp = /* True */0;
        break;
    case /* False */1 :
        tmp = /* False */1;
        break;
    case /* Maybe */2 :
        tmp = /* Maybe */{
          _0: l10n.encDescription
        };
        break;
    
  }
  var param = Yaml_Zip$OptolithClient.zipByPartition(Int$OptolithClient.show, newApplication, application, (function (prim) {
          return prim[0];
        }), (function (prim) {
          return prim[0];
        }), Maybe$OptolithClient.fromMaybe(/* [] */0, univ.applications), l10n.applications);
  return [
          univ.id,
          {
            id: univ.id,
            name: l10n.name,
            check: [
              univ.check1,
              univ.check2,
              univ.check3
            ],
            encumbrance: tmp,
            gr: univ.gr,
            ic: univ.ic,
            applications: Curry._1(IntMap$OptolithClient.fromList, Pervasives.$at(param[1], param[0])),
            applicationsInput: l10n.applicationsInput,
            uses: Curry._1(IntMap$OptolithClient.fromList, Yaml_Zip$OptolithClient.zipBy(Int$OptolithClient.show, use, (function (prim) {
                        return prim[0];
                      }), (function (prim) {
                        return prim[0];
                      }), Maybe$OptolithClient.fromMaybe(/* [] */0, univ.uses), Maybe$OptolithClient.fromMaybe(/* [] */0, l10n.uses))),
            tools: l10n.tools,
            quality: l10n.quality,
            failed: l10n.failed,
            critical: l10n.critical,
            botch: l10n.botch,
            src: l10n.src,
            errata: l10n.errata
          }
        ];
}

function all(yamlData) {
  return Curry._1(IntMap$OptolithClient.fromList, Yaml_Zip$OptolithClient.zipBy(Int$OptolithClient.show, t, (function (x) {
                    return x.id;
                  }), (function (x) {
                    return x.id;
                  }), Json_decode.list(tUniv, yamlData.skillsUniv), Json_decode.list(tL10n, yamlData.skillsL10n)));
}

function group(json) {
  return {
          id: Json_decode.field("id", Json_decode.$$int, json),
          name: Json_decode.field("name", Json_decode.string, json),
          fullName: Json_decode.field("fullName", Json_decode.string, json)
        };
}

function groups(yamlData) {
  return Curry._1(IntMap$OptolithClient.fromList, ListH$OptolithClient.map((function (x) {
                    return [
                            x.id,
                            x
                          ];
                  }), Json_decode.list(group, yamlData.skillGroupsL10n)));
}

var Decode = {
  applicationL10n: applicationL10n,
  useL10n: useL10n,
  tL10n: tL10n,
  applicationUniv: applicationUniv,
  useUniv: useUniv,
  encumbranceUniv: encumbranceUniv,
  tUniv: tUniv,
  newApplication: newApplication,
  application: application,
  use: use,
  t: t,
  all: all,
  group: group,
  groups: groups
};

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