'use strict';

var object = require('./object-037ab45c.js');
require('json-stringify-deterministic');
require('immer');
require('crypto');
require('fs');
require('https');
require('path');

const createEmptyDocumentModelState = () => ({
  id: object.hashKey(),
  name: "",
  extension: "",
  description: "",
  author: {
    name: "",
    website: ""
  },
  state: {
    schema: "",
    examples: []
  },
  modules: []
});
const dateTimeNow = (/* @__PURE__ */ new Date()).toISOString();
const createEmptyExtendedDocumentModelState = () => ({
  // Component 1: document header
  name: "",
  created: dateTimeNow,
  lastModified: dateTimeNow,
  documentType: "powerhouse/document-model",
  revision: 0,
  // Component 2: (strict) state object
  // TODO: rename data to state
  data: createEmptyDocumentModelState(),
  // Component 3: file registry
  fileRegistry: {},
  // TODO: remove operations, lift to the document level structure: operations = { fileRegistry:File[], history:Operation[] }
  operations: [],
  // TODO: remove initialState, lift to the document level (with type: ExtendedDocumentModelState)
  initialState: {
    name: "",
    created: dateTimeNow,
    lastModified: dateTimeNow,
    documentType: "powerhouse/document-model",
    revision: 0,
    data: createEmptyDocumentModelState(),
    fileRegistry: {},
    operations: []
  }
});

// node_modules/@acaldas/document-model-graphql/dist/document-model.js
var r = (e) => e != null;
var J = object.z.any().refine((e) => r(e));
function i() {
  return object.z.object({
    description: object.z.string().nullish(),
    name: object.z.string()
  });
}
function o() {
  return object.z.object({
    errorCode: object.z.string().nullish(),
    errorDescription: object.z.string().nullish(),
    errorName: object.z.string().nullish(),
    errorTemplate: object.z.string().nullish(),
    operationId: object.z.string()
  });
}
function u() {
  return object.z.object({
    example: object.z.string(),
    operationId: object.z.string()
  });
}
function a() {
  return object.z.object({
    description: object.z.string().nullish(),
    moduleId: object.z.string(),
    name: object.z.string(),
    reducer: object.z.string().nullish(),
    schema: object.z.string().nullish(),
    template: object.z.string().nullish()
  });
}
function c() {
  return object.z.object({
    example: object.z.string(),
    insertBefore: object.z.string().nullish()
  });
}
function s() {
  return object.z.object({
    __typename: object.z.literal("Author").optional(),
    name: object.z.string(),
    website: object.z.string().nullish()
  });
}
function n() {
  return object.z.object({
    __typename: object.z.literal("CodeExample").optional(),
    id: object.z.string(),
    value: object.z.string()
  });
}
function l() {
  return object.z.object({
    id: object.z.string()
  });
}
function p() {
  return object.z.object({
    id: object.z.string()
  });
}
function m() {
  return object.z.object({
    id: object.z.string()
  });
}
function d() {
  return object.z.object({
    id: object.z.string()
  });
}
function h() {
  return object.z.object({
    id: object.z.string()
  });
}
function K() {
  return object.z.union([i(), o(), u(), a(), c(), l(), p(), m(), d(), h(), S(), I(), j(), O(), y(), E(), x(), M(), _(), D(), N(), A(), R(), C(), T(), z2(), v(), w(), U(), W(), B(), P(), k(), q(), G(), H()]);
}
function L() {
  return object.z.object({
    __typename: object.z.literal("DocumentModelState").optional(),
    author: s(),
    description: object.z.string(),
    extension: object.z.string(),
    id: object.z.string(),
    modules: object.z.array(g()),
    name: object.z.string(),
    state: F()
  });
}
function g() {
  return object.z.object({
    __typename: object.z.literal("Module").optional(),
    description: object.z.string().nullish(),
    id: object.z.string(),
    name: object.z.string(),
    operations: object.z.array(f())
  });
}
function S() {
  return object.z.object({
    newModuleId: object.z.string(),
    operationId: object.z.string()
  });
}
function f() {
  return object.z.object({
    __typename: object.z.literal("Operation").optional(),
    description: object.z.string().nullish(),
    errors: object.z.array(b()),
    examples: object.z.array(n()),
    id: object.z.string(),
    name: object.z.string().nullish(),
    reducer: object.z.string().nullish(),
    schema: object.z.string().nullish(),
    template: object.z.string().nullish()
  });
}
function b() {
  return object.z.object({
    __typename: object.z.literal("OperationError").optional(),
    code: object.z.string().nullish(),
    description: object.z.string().nullish(),
    id: object.z.string(),
    name: object.z.string().nullish(),
    template: object.z.string().nullish()
  });
}
function I() {
  return object.z.object({
    moduleId: object.z.string(),
    order: object.z.array(object.z.string())
  });
}
function j() {
  return object.z.object({
    order: object.z.array(object.z.string())
  });
}
function O() {
  return object.z.object({
    operationId: object.z.string(),
    order: object.z.array(object.z.string())
  });
}
function y() {
  return object.z.object({
    operationId: object.z.string(),
    order: object.z.array(object.z.string())
  });
}
function E() {
  return object.z.object({
    order: object.z.array(object.z.string())
  });
}
function x() {
  return object.z.object({
    authorName: object.z.string()
  });
}
function M() {
  return object.z.object({
    authorWebsite: object.z.string()
  });
}
function _() {
  return object.z.object({
    description: object.z.string()
  });
}
function D() {
  return object.z.object({
    extension: object.z.string()
  });
}
function N() {
  return object.z.object({
    id: object.z.string()
  });
}
function A() {
  return object.z.object({
    name: object.z.string()
  });
}
function R() {
  return object.z.object({
    description: object.z.string().nullish(),
    id: object.z.string()
  });
}
function C() {
  return object.z.object({
    id: object.z.string(),
    name: object.z.string().nullish()
  });
}
function T() {
  return object.z.object({
    description: object.z.string().nullish(),
    id: object.z.string()
  });
}
function z2() {
  return object.z.object({
    errorCode: object.z.string().nullish(),
    id: object.z.string()
  });
}
function v() {
  return object.z.object({
    errorDescription: object.z.string().nullish(),
    id: object.z.string()
  });
}
function w() {
  return object.z.object({
    errorName: object.z.string().nullish(),
    id: object.z.string()
  });
}
function U() {
  return object.z.object({
    errorTemplate: object.z.string().nullish(),
    id: object.z.string()
  });
}
function W() {
  return object.z.object({
    id: object.z.string(),
    name: object.z.string().nullish()
  });
}
function B() {
  return object.z.object({
    id: object.z.string(),
    reducer: object.z.string().nullish()
  });
}
function P() {
  return object.z.object({
    id: object.z.string(),
    schema: object.z.string().nullish()
  });
}
function k() {
  return object.z.object({
    id: object.z.string(),
    template: object.z.string().nullish()
  });
}
function q() {
  return object.z.object({
    schema: object.z.string()
  });
}
function F() {
  return object.z.object({
    __typename: object.z.literal("State").optional(),
    examples: object.z.array(n()),
    schema: object.z.string()
  });
}
function G() {
  return object.z.object({
    example: object.z.string(),
    id: object.z.string()
  });
}
function H() {
  return object.z.object({
    id: object.z.string(),
    newExample: object.z.string()
  });
}
var V = Object.freeze(Object.defineProperty({
  __proto__: null,
  AddModuleInputSchema: i,
  AddOperationErrorInputSchema: o,
  AddOperationExampleInputSchema: u,
  AddOperationInputSchema: a,
  AddStateExampleInputSchema: c,
  AuthorSchema: s,
  CodeExampleSchema: n,
  DeleteModuleInputSchema: l,
  DeleteOperationErrorInputSchema: p,
  DeleteOperationExampleInputSchema: m,
  DeleteOperationInputSchema: d,
  DeleteStateExampleInputSchema: h,
  DocumentModelInputSchema: K,
  DocumentModelStateSchema: L,
  ModuleSchema: g,
  MoveOperationInputSchema: S,
  OperationErrorSchema: b,
  OperationSchema: f,
  ReorderModuleOperationsInputSchema: I,
  ReorderModulesInputSchema: j,
  ReorderOperationErrorsInputSchema: O,
  ReorderOperationExamplesInputSchema: y,
  ReorderStateExamplesInputSchema: E,
  SetAuthorNameInputSchema: x,
  SetAuthorWebsiteInputSchema: M,
  SetModelDescriptionInputSchema: _,
  SetModelExtensionInputSchema: D,
  SetModelIdInputSchema: N,
  SetModelNameInputSchema: A,
  SetModuleDescriptionInputSchema: R,
  SetModuleNameInputSchema: C,
  SetOperationDescriptionInputSchema: T,
  SetOperationErrorCodeInputSchema: z2,
  SetOperationErrorDescriptionInputSchema: v,
  SetOperationErrorNameInputSchema: w,
  SetOperationErrorTemplateInputSchema: U,
  SetOperationNameInputSchema: W,
  SetOperationReducerInputSchema: B,
  SetOperationSchemaInputSchema: P,
  SetOperationTemplateInputSchema: k,
  SetStateSchemaInputSchema: q,
  StateSchema: F,
  UpdateOperationExampleInputSchema: G,
  UpdateStateExampleInputSchema: H,
  definedNonNullAnySchema: J,
  isDefinedNonNullAny: r
}, Symbol.toStringTag, { value: "Module" }));

const reducer$6 = {
  setModelNameOperation(state, action) {
    state.data.name = action.input.name;
  },
  setModelIdOperation(state, action) {
    state.data.id = action.input.id;
  },
  setModelExtensionOperation(state, action) {
    state.data.extension = action.input.extension;
  },
  setModelDescriptionOperation(state, action) {
    state.data.description = action.input.description;
  },
  setAuthorNameOperation(state, action) {
    state.data.author = state.data.author || { name: "", website: null };
    state.data.author.name = action.input.authorName;
  },
  setAuthorWebsiteOperation(state, action) {
    state.data.author = state.data.author || { name: "", website: null };
    state.data.author.website = action.input.authorWebsite;
  }
};

const moduleSorter = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$5 = {
  addModuleOperation(state, action) {
    state.data.modules.push({
      id: object.hashKey(),
      name: action.input.name,
      description: action.input.description || "",
      operations: []
    });
  },
  setModuleNameOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      if (state.data.modules[i].id === action.input.id) {
        state.data.modules[i].name = action.input.name || "";
      }
    }
  },
  setModuleDescriptionOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      if (state.data.modules[i].id === action.input.id) {
        state.data.modules[i].description = action.input.description || "";
      }
    }
  },
  deleteModuleOperation(state, action) {
    state.data.modules = state.data.modules.filter((m) => m.id != action.input.id);
  },
  reorderModulesOperation(state, action) {
    state.data.modules.sort(moduleSorter(action.input.order));
  }
};

const errorSorter = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$4 = {
  addOperationErrorOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.operationId) {
          state.data.modules[i].operations[j].errors.push({
            id: object.hashKey(),
            name: action.input.errorName || "",
            code: action.input.errorCode || "",
            description: action.input.errorDescription || "",
            template: action.input.errorTemplate || ""
          });
        }
      }
    }
  },
  setOperationErrorCodeOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        for (let k = 0; k < state.data.modules[i].operations[j].errors.length; k++) {
          if (state.data.modules[i].operations[j].errors[k].id == action.input.id) {
            state.data.modules[i].operations[j].errors[k].code = action.input.errorCode || "";
          }
        }
      }
    }
  },
  setOperationErrorNameOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        for (let k = 0; k < state.data.modules[i].operations[j].errors.length; k++) {
          if (state.data.modules[i].operations[j].errors[k].id == action.input.id) {
            state.data.modules[i].operations[j].errors[k].name = action.input.errorName || "";
          }
        }
      }
    }
  },
  setOperationErrorDescriptionOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        for (let k = 0; k < state.data.modules[i].operations[j].errors.length; k++) {
          if (state.data.modules[i].operations[j].errors[k].id == action.input.id) {
            state.data.modules[i].operations[j].errors[k].description = action.input.errorDescription || "";
          }
        }
      }
    }
  },
  setOperationErrorTemplateOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        for (let k = 0; k < state.data.modules[i].operations[j].errors.length; k++) {
          if (state.data.modules[i].operations[j].errors[k].id == action.input.id) {
            state.data.modules[i].operations[j].errors[k].template = action.input.errorTemplate || "";
          }
        }
      }
    }
  },
  deleteOperationErrorOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        state.data.modules[i].operations[j].errors = state.data.modules[i].operations[j].errors.filter((e) => e.id != action.input.id);
      }
    }
  },
  reorderOperationErrorsOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.operationId) {
          state.data.modules[i].operations[j].errors.sort(errorSorter(action.input.order));
        }
      }
    }
  }
};

const exampleSorter$1 = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$3 = {
  addOperationExampleOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.operationId) {
          state.data.modules[i].operations[j].examples.push({
            id: object.hashKey(),
            value: action.input.example
          });
        }
      }
    }
  },
  updateOperationExampleOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        for (let k = 0; k < state.data.modules[i].operations[j].examples.length; k++) {
          if (state.data.modules[i].operations[j].examples[k].id == action.input.id) {
            state.data.modules[i].operations[j].examples[k].value = action.input.example;
          }
        }
      }
    }
  },
  deleteOperationExampleOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        state.data.modules[i].operations[j].examples = state.data.modules[i].operations[j].examples.filter((e) => e.id != action.input.id);
      }
    }
  },
  reorderOperationExamplesOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.operationId) {
          state.data.modules[i].operations[j].examples.sort(exampleSorter$1(action.input.order));
        }
      }
    }
  }
};

const operationSorter = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$2 = {
  addOperationOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      if (state.data.modules[i].id == action.input.moduleId) {
        state.data.modules[i].operations.push({
          id: object.hashKey(),
          name: action.input.name,
          description: action.input.description || "",
          schema: action.input.schema || "",
          template: action.input.template || action.input.description || "",
          reducer: action.input.reducer || "",
          errors: [],
          examples: []
        });
      }
    }
  },
  setOperationNameOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.id) {
          state.data.modules[i].operations[j].name = action.input.name || "";
        }
      }
    }
  },
  setOperationSchemaOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.id) {
          state.data.modules[i].operations[j].schema = action.input.schema || "";
        }
      }
    }
  },
  setOperationDescriptionOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.id) {
          state.data.modules[i].operations[j].description = action.input.description || "";
        }
      }
    }
  },
  setOperationTemplateOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.id) {
          state.data.modules[i].operations[j].template = action.input.template || "";
        }
      }
    }
  },
  setOperationReducerOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      for (let j = 0; j < state.data.modules[i].operations.length; j++) {
        if (state.data.modules[i].operations[j].id == action.input.id) {
          state.data.modules[i].operations[j].reducer = action.input.reducer || "";
        }
      }
    }
  },
  moveOperationOperation(state, action) {
    const moveOperations = [];
    for (let i = 0; i < state.data.modules.length; i++) {
      state.data.modules[i].operations = state.data.modules[i].operations.filter((operation) => {
        if (operation.id == action.input.operationId) {
          moveOperations.push(operation);
          return false;
        }
        return true;
      });
    }
    for (let i = 0; i < state.data.modules.length; i++) {
      if (state.data.modules[i].id == action.input.newModuleId) {
        state.data.modules[i].operations.push(...moveOperations);
      }
    }
  },
  deleteOperationOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      state.data.modules[i].operations = state.data.modules[i].operations.filter((operation) => operation.id != action.input.id);
    }
  },
  reorderModuleOperationsOperation(state, action) {
    for (let i = 0; i < state.data.modules.length; i++) {
      if (state.data.modules[i].id == action.input.moduleId) {
        state.data.modules[i].operations.sort(operationSorter(action.input.order));
      }
    }
  }
};

const exampleSorter = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$1 = {
  setStateSchemaOperation(state, action) {
    state.data.state.schema = action.input.schema;
  },
  addStateExampleOperation(state, action) {
    state.data.state.examples.push({
      id: object.hashKey(),
      value: action.input.example
    });
  },
  updateStateExampleOperation(state, action) {
    for (let i = 0; i < state.data.state.examples.length; i++) {
      if (state.data.state.examples[i].id == action.input.id) {
        state.data.state.examples[i].value = action.input.newExample;
      }
    }
  },
  deleteStateExampleOperation(state, action) {
    state.data.state.examples = state.data.state.examples.filter((e) => e.id != action.input.id);
  },
  reorderStateExamplesOperation(state, action) {
    state.data.state.examples.sort(exampleSorter(action.input.order));
  }
};

const stateReducer = (state, action) => {
  if (object.isBaseAction(action)) {
    return state;
  }
  switch (action.type) {
    case "SET_MODEL_NAME":
      V.SetModelNameInputSchema().parse(action.input);
      reducer$6.setModelNameOperation(state, action);
      break;
    case "SET_MODEL_ID":
      V.SetModelIdInputSchema().parse(action.input);
      reducer$6.setModelIdOperation(state, action);
      break;
    case "SET_MODEL_EXTENSION":
      V.SetModelExtensionInputSchema().parse(action.input);
      reducer$6.setModelExtensionOperation(state, action);
      break;
    case "SET_MODEL_DESCRIPTION":
      V.SetModelDescriptionInputSchema().parse(action.input);
      reducer$6.setModelDescriptionOperation(state, action);
      break;
    case "SET_AUTHOR_NAME":
      V.SetAuthorNameInputSchema().parse(action.input);
      reducer$6.setAuthorNameOperation(state, action);
      break;
    case "SET_AUTHOR_WEBSITE":
      V.SetAuthorWebsiteInputSchema().parse(action.input);
      reducer$6.setAuthorWebsiteOperation(state, action);
      break;
    case "ADD_MODULE":
      V.AddModuleInputSchema().parse(action.input);
      reducer$5.addModuleOperation(state, action);
      break;
    case "SET_MODULE_NAME":
      V.SetModuleNameInputSchema().parse(action.input);
      reducer$5.setModuleNameOperation(state, action);
      break;
    case "SET_MODULE_DESCRIPTION":
      V.SetModuleDescriptionInputSchema().parse(action.input);
      reducer$5.setModuleDescriptionOperation(state, action);
      break;
    case "DELETE_MODULE":
      V.DeleteModuleInputSchema().parse(action.input);
      reducer$5.deleteModuleOperation(state, action);
      break;
    case "REORDER_MODULES":
      V.ReorderModulesInputSchema().parse(action.input);
      reducer$5.reorderModulesOperation(state, action);
      break;
    case "ADD_OPERATION_ERROR":
      V.AddOperationErrorInputSchema().parse(action.input);
      reducer$4.addOperationErrorOperation(state, action);
      break;
    case "SET_OPERATION_ERROR_CODE":
      V.SetOperationErrorCodeInputSchema().parse(action.input);
      reducer$4.setOperationErrorCodeOperation(state, action);
      break;
    case "SET_OPERATION_ERROR_NAME":
      V.SetOperationErrorNameInputSchema().parse(action.input);
      reducer$4.setOperationErrorNameOperation(state, action);
      break;
    case "SET_OPERATION_ERROR_DESCRIPTION":
      V.SetOperationErrorDescriptionInputSchema().parse(action.input);
      reducer$4.setOperationErrorDescriptionOperation(state, action);
      break;
    case "SET_OPERATION_ERROR_TEMPLATE":
      V.SetOperationErrorTemplateInputSchema().parse(action.input);
      reducer$4.setOperationErrorTemplateOperation(state, action);
      break;
    case "DELETE_OPERATION_ERROR":
      V.DeleteOperationErrorInputSchema().parse(action.input);
      reducer$4.deleteOperationErrorOperation(state, action);
      break;
    case "REORDER_OPERATION_ERRORS":
      V.ReorderOperationErrorsInputSchema().parse(action.input);
      reducer$4.reorderOperationErrorsOperation(state, action);
      break;
    case "ADD_OPERATION_EXAMPLE":
      V.AddOperationExampleInputSchema().parse(action.input);
      reducer$3.addOperationExampleOperation(state, action);
      break;
    case "UPDATE_OPERATION_EXAMPLE":
      V.UpdateOperationExampleInputSchema().parse(action.input);
      reducer$3.updateOperationExampleOperation(state, action);
      break;
    case "DELETE_OPERATION_EXAMPLE":
      V.DeleteOperationExampleInputSchema().parse(action.input);
      reducer$3.deleteOperationExampleOperation(state, action);
      break;
    case "REORDER_OPERATION_EXAMPLES":
      V.ReorderOperationExamplesInputSchema().parse(action.input);
      reducer$3.reorderOperationExamplesOperation(state, action);
      break;
    case "ADD_OPERATION":
      V.AddOperationInputSchema().parse(action.input);
      reducer$2.addOperationOperation(state, action);
      break;
    case "SET_OPERATION_NAME":
      V.SetOperationNameInputSchema().parse(action.input);
      reducer$2.setOperationNameOperation(state, action);
      break;
    case "SET_OPERATION_SCHEMA":
      V.SetOperationSchemaInputSchema().parse(action.input);
      reducer$2.setOperationSchemaOperation(state, action);
      break;
    case "SET_OPERATION_DESCRIPTION":
      V.SetOperationDescriptionInputSchema().parse(action.input);
      reducer$2.setOperationDescriptionOperation(state, action);
      break;
    case "SET_OPERATION_TEMPLATE":
      V.SetOperationTemplateInputSchema().parse(action.input);
      reducer$2.setOperationTemplateOperation(state, action);
      break;
    case "SET_OPERATION_REDUCER":
      V.SetOperationReducerInputSchema().parse(action.input);
      reducer$2.setOperationReducerOperation(state, action);
      break;
    case "MOVE_OPERATION":
      V.MoveOperationInputSchema().parse(action.input);
      reducer$2.moveOperationOperation(state, action);
      break;
    case "DELETE_OPERATION":
      V.DeleteOperationInputSchema().parse(action.input);
      reducer$2.deleteOperationOperation(state, action);
      break;
    case "REORDER_MODULE_OPERATIONS":
      V.ReorderModuleOperationsInputSchema().parse(action.input);
      reducer$2.reorderModuleOperationsOperation(state, action);
      break;
    case "SET_STATE_SCHEMA":
      V.SetStateSchemaInputSchema().parse(action.input);
      reducer$1.setStateSchemaOperation(state, action);
      break;
    case "ADD_STATE_EXAMPLE":
      V.AddStateExampleInputSchema().parse(action.input);
      reducer$1.addStateExampleOperation(state, action);
      break;
    case "UPDATE_STATE_EXAMPLE":
      V.UpdateStateExampleInputSchema().parse(action.input);
      reducer$1.updateStateExampleOperation(state, action);
      break;
    case "DELETE_STATE_EXAMPLE":
      V.DeleteStateExampleInputSchema().parse(action.input);
      reducer$1.deleteStateExampleOperation(state, action);
      break;
    case "REORDER_STATE_EXAMPLES":
      V.ReorderStateExamplesInputSchema().parse(action.input);
      reducer$1.reorderStateExamplesOperation(state, action);
      break;
    default:
      return state;
  }
};
const reducer = object.createReducer(stateReducer);

const setModelName = (input) => object.createAction(
  "SET_MODEL_NAME",
  { ...input }
);
const setModelId = (input) => object.createAction(
  "SET_MODEL_ID",
  { ...input }
);
const setModelExtension = (input) => object.createAction(
  "SET_MODEL_EXTENSION",
  { ...input }
);
const setModelDescription = (input) => object.createAction(
  "SET_MODEL_DESCRIPTION",
  { ...input }
);
const setAuthorName = (input) => object.createAction(
  "SET_AUTHOR_NAME",
  { ...input }
);
const setAuthorWebsite = (input) => object.createAction(
  "SET_AUTHOR_WEBSITE",
  { ...input }
);

class DocumentModel_Header extends object.BaseDocument {
  setModelName(input) {
    return this.dispatch(setModelName(input));
  }
  setModelId(input) {
    return this.dispatch(setModelId(input));
  }
  setModelExtension(input) {
    return this.dispatch(setModelExtension(input));
  }
  setModelDescription(input) {
    return this.dispatch(setModelDescription(input));
  }
  setAuthorName(input) {
    return this.dispatch(setAuthorName(input));
  }
  setAuthorWebsite(input) {
    return this.dispatch(setAuthorWebsite(input));
  }
}

const addModule = (input) => object.createAction(
  "ADD_MODULE",
  { ...input }
);
const setModuleName = (input) => object.createAction(
  "SET_MODULE_NAME",
  { ...input }
);
const setModuleDescription = (input) => object.createAction(
  "SET_MODULE_DESCRIPTION",
  { ...input }
);
const deleteModule = (input) => object.createAction(
  "DELETE_MODULE",
  { ...input }
);
const reorderModules = (input) => object.createAction(
  "REORDER_MODULES",
  { ...input }
);

class DocumentModel_Module extends object.BaseDocument {
  addModule(input) {
    return this.dispatch(addModule(input));
  }
  setModuleName(input) {
    return this.dispatch(setModuleName(input));
  }
  setModuleDescription(input) {
    return this.dispatch(setModuleDescription(input));
  }
  deleteModule(input) {
    return this.dispatch(deleteModule(input));
  }
  reorderModules(input) {
    return this.dispatch(reorderModules(input));
  }
}

const addOperationError = (input) => object.createAction(
  "ADD_OPERATION_ERROR",
  { ...input }
);
const setOperationErrorCode = (input) => object.createAction(
  "SET_OPERATION_ERROR_CODE",
  { ...input }
);
const setOperationErrorName = (input) => object.createAction(
  "SET_OPERATION_ERROR_NAME",
  { ...input }
);
const setOperationErrorDescription = (input) => object.createAction(
  "SET_OPERATION_ERROR_DESCRIPTION",
  { ...input }
);
const setOperationErrorTemplate = (input) => object.createAction(
  "SET_OPERATION_ERROR_TEMPLATE",
  { ...input }
);
const deleteOperationError = (input) => object.createAction(
  "DELETE_OPERATION_ERROR",
  { ...input }
);
const reorderOperationErrors = (input) => object.createAction(
  "REORDER_OPERATION_ERRORS",
  { ...input }
);

class DocumentModel_OperationError extends object.BaseDocument {
  addOperationError(input) {
    return this.dispatch(addOperationError(input));
  }
  setOperationErrorCode(input) {
    return this.dispatch(setOperationErrorCode(input));
  }
  setOperationErrorName(input) {
    return this.dispatch(setOperationErrorName(input));
  }
  setOperationErrorDescription(input) {
    return this.dispatch(setOperationErrorDescription(input));
  }
  setOperationErrorTemplate(input) {
    return this.dispatch(setOperationErrorTemplate(input));
  }
  deleteOperationError(input) {
    return this.dispatch(deleteOperationError(input));
  }
  reorderOperationErrors(input) {
    return this.dispatch(reorderOperationErrors(input));
  }
}

const addOperationExample = (input) => object.createAction(
  "ADD_OPERATION_EXAMPLE",
  { ...input }
);
const updateOperationExample = (input) => object.createAction(
  "UPDATE_OPERATION_EXAMPLE",
  { ...input }
);
const deleteOperationExample = (input) => object.createAction(
  "DELETE_OPERATION_EXAMPLE",
  { ...input }
);
const reorderOperationExamples = (input) => object.createAction(
  "REORDER_OPERATION_EXAMPLES",
  { ...input }
);

class DocumentModel_OperationExample extends object.BaseDocument {
  addOperationExample(input) {
    return this.dispatch(addOperationExample(input));
  }
  updateOperationExample(input) {
    return this.dispatch(updateOperationExample(input));
  }
  deleteOperationExample(input) {
    return this.dispatch(deleteOperationExample(input));
  }
  reorderOperationExamples(input) {
    return this.dispatch(reorderOperationExamples(input));
  }
}

const addOperation = (input) => object.createAction(
  "ADD_OPERATION",
  { ...input }
);
const setOperationName = (input) => object.createAction(
  "SET_OPERATION_NAME",
  { ...input }
);
const setOperationSchema = (input) => object.createAction(
  "SET_OPERATION_SCHEMA",
  { ...input }
);
const setOperationDescription = (input) => object.createAction(
  "SET_OPERATION_DESCRIPTION",
  { ...input }
);
const setOperationTemplate = (input) => object.createAction(
  "SET_OPERATION_TEMPLATE",
  { ...input }
);
const setOperationReducer = (input) => object.createAction(
  "SET_OPERATION_REDUCER",
  { ...input }
);
const moveOperation = (input) => object.createAction(
  "MOVE_OPERATION",
  { ...input }
);
const deleteOperation = (input) => object.createAction(
  "DELETE_OPERATION",
  { ...input }
);
const reorderModuleOperations = (input) => object.createAction(
  "REORDER_MODULE_OPERATIONS",
  { ...input }
);

class DocumentModel_Operation extends object.BaseDocument {
  addOperation(input) {
    return this.dispatch(addOperation(input));
  }
  setOperationName(input) {
    return this.dispatch(setOperationName(input));
  }
  setOperationSchema(input) {
    return this.dispatch(setOperationSchema(input));
  }
  setOperationDescription(input) {
    return this.dispatch(setOperationDescription(input));
  }
  setOperationTemplate(input) {
    return this.dispatch(setOperationTemplate(input));
  }
  setOperationReducer(input) {
    return this.dispatch(setOperationReducer(input));
  }
  moveOperation(input) {
    return this.dispatch(moveOperation(input));
  }
  deleteOperation(input) {
    return this.dispatch(deleteOperation(input));
  }
  reorderModuleOperations(input) {
    return this.dispatch(reorderModuleOperations(input));
  }
}

const setStateSchema = (input) => object.createAction(
  "SET_STATE_SCHEMA",
  { ...input }
);
const addStateExample = (input) => object.createAction(
  "ADD_STATE_EXAMPLE",
  { ...input }
);
const updateStateExample = (input) => object.createAction(
  "UPDATE_STATE_EXAMPLE",
  { ...input }
);
const deleteStateExample = (input) => object.createAction(
  "DELETE_STATE_EXAMPLE",
  { ...input }
);
const reorderStateExamples = (input) => object.createAction(
  "REORDER_STATE_EXAMPLES",
  { ...input }
);

class DocumentModel_State extends object.BaseDocument {
  setStateSchema(input) {
    return this.dispatch(setStateSchema(input));
  }
  addStateExample(input) {
    return this.dispatch(addStateExample(input));
  }
  updateStateExample(input) {
    return this.dispatch(updateStateExample(input));
  }
  deleteStateExample(input) {
    return this.dispatch(deleteStateExample(input));
  }
  reorderStateExamples(input) {
    return this.dispatch(reorderStateExamples(input));
  }
}

let DocumentModel$2 = class DocumentModel extends object.BaseDocument {
  static fileExtension = "phdm";
  get state() {
    return this._state.data;
  }
  constructor(initialState) {
    super(reducer, initialState || createEmptyExtendedDocumentModelState());
  }
  saveToFile(path, name) {
    return super.saveToFile(path, DocumentModel.fileExtension, name);
  }
  loadFromFile(path) {
    return super.loadFromFile(path);
  }
  static async fromFile(path) {
    const document = new this();
    await document.loadFromFile(path);
    return document;
  }
};
object.applyMixins(DocumentModel$2, [
  DocumentModel_Header,
  DocumentModel_Module,
  DocumentModel_OperationError,
  DocumentModel_OperationExample,
  DocumentModel_Operation,
  DocumentModel_State
]);

var gen = /*#__PURE__*/Object.freeze({
    __proto__: null,
    DocumentModel: DocumentModel$2,
    addModule: addModule,
    addOperation: addOperation,
    addOperationError: addOperationError,
    addOperationExample: addOperationExample,
    addStateExample: addStateExample,
    deleteModule: deleteModule,
    deleteOperation: deleteOperation,
    deleteOperationError: deleteOperationError,
    deleteOperationExample: deleteOperationExample,
    deleteStateExample: deleteStateExample,
    moveOperation: moveOperation,
    reorderModuleOperations: reorderModuleOperations,
    reorderModules: reorderModules,
    reorderOperationErrors: reorderOperationErrors,
    reorderOperationExamples: reorderOperationExamples,
    reorderStateExamples: reorderStateExamples,
    setAuthorName: setAuthorName,
    setAuthorWebsite: setAuthorWebsite,
    setModelDescription: setModelDescription,
    setModelExtension: setModelExtension,
    setModelId: setModelId,
    setModelName: setModelName,
    setModuleDescription: setModuleDescription,
    setModuleName: setModuleName,
    setOperationDescription: setOperationDescription,
    setOperationErrorCode: setOperationErrorCode,
    setOperationErrorDescription: setOperationErrorDescription,
    setOperationErrorName: setOperationErrorName,
    setOperationErrorTemplate: setOperationErrorTemplate,
    setOperationName: setOperationName,
    setOperationReducer: setOperationReducer,
    setOperationSchema: setOperationSchema,
    setOperationTemplate: setOperationTemplate,
    setStateSchema: setStateSchema,
    updateOperationExample: updateOperationExample,
    updateStateExample: updateStateExample
});

const { DocumentModel, ...DocumentModelActions } = gen;
const actions = { ...object.BaseActions, ...DocumentModelActions };

var DocumentModel$1 = /*#__PURE__*/Object.freeze({
    __proto__: null,
    DocumentModel: DocumentModel,
    actions: actions,
    createEmptyDocumentModelState: createEmptyDocumentModelState,
    createEmptyExtendedDocumentModelState: createEmptyExtendedDocumentModelState,
    reducer: reducer
});

exports.DocumentModel = DocumentModel$1;
exports.DocumentModel$1 = DocumentModel;
exports.actions = actions;
exports.createEmptyDocumentModelState = createEmptyDocumentModelState;
exports.createEmptyExtendedDocumentModelState = createEmptyExtendedDocumentModelState;
exports.reducer = reducer;
//# sourceMappingURL=index-3c9a83d3.js.map
