import { h as hashKey, z, c as createReducer, i as isBaseAction, a as createAction, B as BaseDocument, b as applyMixins, d as BaseActions } from './object-693686d0.js';
import 'json-stringify-deterministic';
import 'immer';
import 'crypto';
import 'fs';
import 'https';
import 'path';

const createEmptyDocumentModelState = () => ({
  id: 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 = z.any().refine((e) => r(e));
function i() {
  return z.object({
    description: z.string().nullish(),
    name: z.string()
  });
}
function o() {
  return z.object({
    errorCode: z.string().nullish(),
    errorDescription: z.string().nullish(),
    errorName: z.string().nullish(),
    errorTemplate: z.string().nullish(),
    operationId: z.string()
  });
}
function u() {
  return z.object({
    example: z.string(),
    operationId: z.string()
  });
}
function a() {
  return z.object({
    description: z.string().nullish(),
    moduleId: z.string(),
    name: z.string(),
    reducer: z.string().nullish(),
    schema: z.string().nullish(),
    template: z.string().nullish()
  });
}
function c() {
  return z.object({
    example: z.string(),
    insertBefore: z.string().nullish()
  });
}
function s() {
  return z.object({
    __typename: z.literal("Author").optional(),
    name: z.string(),
    website: z.string().nullish()
  });
}
function n() {
  return z.object({
    __typename: z.literal("CodeExample").optional(),
    id: z.string(),
    value: z.string()
  });
}
function l() {
  return z.object({
    id: z.string()
  });
}
function p() {
  return z.object({
    id: z.string()
  });
}
function m() {
  return z.object({
    id: z.string()
  });
}
function d() {
  return z.object({
    id: z.string()
  });
}
function h() {
  return z.object({
    id: z.string()
  });
}
function K() {
  return 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 z.object({
    __typename: z.literal("DocumentModelState").optional(),
    author: s(),
    description: z.string(),
    extension: z.string(),
    id: z.string(),
    modules: z.array(g()),
    name: z.string(),
    state: F()
  });
}
function g() {
  return z.object({
    __typename: z.literal("Module").optional(),
    description: z.string().nullish(),
    id: z.string(),
    name: z.string(),
    operations: z.array(f())
  });
}
function S() {
  return z.object({
    newModuleId: z.string(),
    operationId: z.string()
  });
}
function f() {
  return z.object({
    __typename: z.literal("Operation").optional(),
    description: z.string().nullish(),
    errors: z.array(b()),
    examples: z.array(n()),
    id: z.string(),
    name: z.string().nullish(),
    reducer: z.string().nullish(),
    schema: z.string().nullish(),
    template: z.string().nullish()
  });
}
function b() {
  return z.object({
    __typename: z.literal("OperationError").optional(),
    code: z.string().nullish(),
    description: z.string().nullish(),
    id: z.string(),
    name: z.string().nullish(),
    template: z.string().nullish()
  });
}
function I() {
  return z.object({
    moduleId: z.string(),
    order: z.array(z.string())
  });
}
function j() {
  return z.object({
    order: z.array(z.string())
  });
}
function O() {
  return z.object({
    operationId: z.string(),
    order: z.array(z.string())
  });
}
function y() {
  return z.object({
    operationId: z.string(),
    order: z.array(z.string())
  });
}
function E() {
  return z.object({
    order: z.array(z.string())
  });
}
function x() {
  return z.object({
    authorName: z.string()
  });
}
function M() {
  return z.object({
    authorWebsite: z.string()
  });
}
function _() {
  return z.object({
    description: z.string()
  });
}
function D() {
  return z.object({
    extension: z.string()
  });
}
function N() {
  return z.object({
    id: z.string()
  });
}
function A() {
  return z.object({
    name: z.string()
  });
}
function R() {
  return z.object({
    description: z.string().nullish(),
    id: z.string()
  });
}
function C() {
  return z.object({
    id: z.string(),
    name: z.string().nullish()
  });
}
function T() {
  return z.object({
    description: z.string().nullish(),
    id: z.string()
  });
}
function z2() {
  return z.object({
    errorCode: z.string().nullish(),
    id: z.string()
  });
}
function v() {
  return z.object({
    errorDescription: z.string().nullish(),
    id: z.string()
  });
}
function w() {
  return z.object({
    errorName: z.string().nullish(),
    id: z.string()
  });
}
function U() {
  return z.object({
    errorTemplate: z.string().nullish(),
    id: z.string()
  });
}
function W() {
  return z.object({
    id: z.string(),
    name: z.string().nullish()
  });
}
function B() {
  return z.object({
    id: z.string(),
    reducer: z.string().nullish()
  });
}
function P() {
  return z.object({
    id: z.string(),
    schema: z.string().nullish()
  });
}
function k() {
  return z.object({
    id: z.string(),
    template: z.string().nullish()
  });
}
function q() {
  return z.object({
    schema: z.string()
  });
}
function F() {
  return z.object({
    __typename: z.literal("State").optional(),
    examples: z.array(n()),
    schema: z.string()
  });
}
function G() {
  return z.object({
    example: z.string(),
    id: z.string()
  });
}
function H() {
  return z.object({
    id: z.string(),
    newExample: 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: 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: 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: 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: 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: 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 (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 = createReducer(stateReducer);

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

class DocumentModel_Header extends 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) => createAction(
  "ADD_MODULE",
  { ...input }
);
const setModuleName = (input) => createAction(
  "SET_MODULE_NAME",
  { ...input }
);
const setModuleDescription = (input) => createAction(
  "SET_MODULE_DESCRIPTION",
  { ...input }
);
const deleteModule = (input) => createAction(
  "DELETE_MODULE",
  { ...input }
);
const reorderModules = (input) => createAction(
  "REORDER_MODULES",
  { ...input }
);

class DocumentModel_Module extends 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) => createAction(
  "ADD_OPERATION_ERROR",
  { ...input }
);
const setOperationErrorCode = (input) => createAction(
  "SET_OPERATION_ERROR_CODE",
  { ...input }
);
const setOperationErrorName = (input) => createAction(
  "SET_OPERATION_ERROR_NAME",
  { ...input }
);
const setOperationErrorDescription = (input) => createAction(
  "SET_OPERATION_ERROR_DESCRIPTION",
  { ...input }
);
const setOperationErrorTemplate = (input) => createAction(
  "SET_OPERATION_ERROR_TEMPLATE",
  { ...input }
);
const deleteOperationError = (input) => createAction(
  "DELETE_OPERATION_ERROR",
  { ...input }
);
const reorderOperationErrors = (input) => createAction(
  "REORDER_OPERATION_ERRORS",
  { ...input }
);

class DocumentModel_OperationError extends 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) => createAction(
  "ADD_OPERATION_EXAMPLE",
  { ...input }
);
const updateOperationExample = (input) => createAction(
  "UPDATE_OPERATION_EXAMPLE",
  { ...input }
);
const deleteOperationExample = (input) => createAction(
  "DELETE_OPERATION_EXAMPLE",
  { ...input }
);
const reorderOperationExamples = (input) => createAction(
  "REORDER_OPERATION_EXAMPLES",
  { ...input }
);

class DocumentModel_OperationExample extends 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) => createAction(
  "ADD_OPERATION",
  { ...input }
);
const setOperationName = (input) => createAction(
  "SET_OPERATION_NAME",
  { ...input }
);
const setOperationSchema = (input) => createAction(
  "SET_OPERATION_SCHEMA",
  { ...input }
);
const setOperationDescription = (input) => createAction(
  "SET_OPERATION_DESCRIPTION",
  { ...input }
);
const setOperationTemplate = (input) => createAction(
  "SET_OPERATION_TEMPLATE",
  { ...input }
);
const setOperationReducer = (input) => createAction(
  "SET_OPERATION_REDUCER",
  { ...input }
);
const moveOperation = (input) => createAction(
  "MOVE_OPERATION",
  { ...input }
);
const deleteOperation = (input) => createAction(
  "DELETE_OPERATION",
  { ...input }
);
const reorderModuleOperations = (input) => createAction(
  "REORDER_MODULE_OPERATIONS",
  { ...input }
);

class DocumentModel_Operation extends 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) => createAction(
  "SET_STATE_SCHEMA",
  { ...input }
);
const addStateExample = (input) => createAction(
  "ADD_STATE_EXAMPLE",
  { ...input }
);
const updateStateExample = (input) => createAction(
  "UPDATE_STATE_EXAMPLE",
  { ...input }
);
const deleteStateExample = (input) => createAction(
  "DELETE_STATE_EXAMPLE",
  { ...input }
);
const reorderStateExamples = (input) => createAction(
  "REORDER_STATE_EXAMPLES",
  { ...input }
);

class DocumentModel_State extends 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 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;
  }
};
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 = { ...BaseActions, ...DocumentModelActions };

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

export { DocumentModel$1 as D, actions as a, DocumentModel as b, createEmptyDocumentModelState as c, createEmptyExtendedDocumentModelState as d, reducer as r };
//# sourceMappingURL=index-79c8466d.js.map
