import{G as e,J as t,K as n,Q as r,U as i,W as a,X as o,_t as s,bt as c,ht as l,it as u,mt as d,pt as f,q as p,tt as m,vt as h,w as g,wt as _,xt as v}from"./lz-string-CMojKG3P.js";import{t as y}from"./chunk-pbuEa-1d-DjY3kn7w.js";var b={id:`powerhouse/processor`,name:`Processor Module`,extension:`.phdm`,description:``,author:{name:`Powerhouse`,website:`https://powerhouse.inc`},specifications:[{version:1,changeLog:[],state:{global:{schema:`type ProcessorModuleState {
  name: String!
  type: String!
  documentTypes: [DocumentTypeItem!]!
  status: StatusType!
 processorApps: [String!]! 
}

type DocumentTypeItem {
  id: OID!
  documentType: String!
}

enum StatusType {
  DRAFT
  CONFIRMED
}`,initialValue:`{
  "name": "",
  "type": "",
  "documentTypes": [],
  "status": "DRAFT",
 processorApps: [] 
}`,examples:[]},local:{schema:``,initialValue:``,examples:[]}},modules:[{id:`91ad39c1-4e8b-4127-b3c8-e835b85e6360`,name:`base_operations`,description:``,operations:[{id:`6f3a5c90-39f2-4302-a073-6195a71c5054`,name:`SET_PROCESSOR_NAME`,description:``,schema:`input SetProcessorNameInput {
  name: String!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`b8f28bb4-c6ae-40e6-86fa-29ef14ff8667`,name:`SET_PROCESSOR_TYPE`,description:``,schema:`input SetProcessorTypeInput {
  type: String!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`fbbd7a71-c495-4efc-b8f6-1e57798dbbb4`,name:`ADD_DOCUMENT_TYPE`,description:``,schema:`input AddDocumentTypeInput {
  id: OID!
  documentType: String!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`544d413f-423c-4d97-9570-84a19bffeab9`,name:`REMOVE_DOCUMENT_TYPE`,description:``,schema:`input RemoveDocumentTypeInput {
  id: OID!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`df5eb500-7308-498c-9b80-028878ee198b`,name:`ADD_PROCESSOR_APP`,description:``,schema:`input AddProcessorAppInput {
 processorApp: String! 
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`07e4168f-1a7b-41ef-953d-219028be7bb9`,name:`REMOVE_PROCESSOR_APP`,description:``,schema:`input RemoveProcessorAppInput {
 processorApp: String! 
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`},{id:`7b6706eb-5e25-4d64-829a-e3a251380fd1`,name:`SET_PROCESSOR_STATUS`,description:``,schema:`input SetProcessorStatusInput {
  status: StatusType!
}`,template:``,reducer:``,errors:[],examples:[],scope:`global`}]}]}]},x=e=>e!=null;d().refine(e=>x(e));var S=f([`CONFIRMED`,`DRAFT`]);function C(){return c({documentType:v(),id:v()})}function w(){return c({processorApp:v()})}function T(){return c({__typename:h(`DocumentTypeItem`).optional(),documentType:v(),id:v()})}function E(){return c({__typename:h(`ProcessorModuleState`).optional(),documentTypes:l(s(()=>T())),name:v(),processorApps:l(v()),status:S,type:v()})}function D(){return c({id:v()})}function O(){return c({processorApp:v()})}function k(){return c({name:v()})}function A(){return c({status:S})}function j(){return c({type:v()})}var M=y({addDocumentType:()=>F,addProcessorApp:()=>L,removeDocumentType:()=>I,removeProcessorApp:()=>R,setProcessorName:()=>N,setProcessorStatus:()=>z,setProcessorType:()=>P}),N=e=>o(`SET_PROCESSOR_NAME`,{...e},void 0,k,`global`),P=e=>o(`SET_PROCESSOR_TYPE`,{...e},void 0,j,`global`),F=e=>o(`ADD_DOCUMENT_TYPE`,{...e},void 0,C,`global`),I=e=>o(`REMOVE_DOCUMENT_TYPE`,{...e},void 0,D,`global`),L=e=>o(`ADD_PROCESSOR_APP`,{...e},void 0,w,`global`),R=e=>o(`REMOVE_PROCESSOR_APP`,{...e},void 0,O,`global`),z=e=>o(`SET_PROCESSOR_STATUS`,{...e},void 0,A,`global`),B=`powerhouse/processor`,V=i.extend({documentType:h(B)}),H=a.extend({global:E()}),U=c({header:V,state:H,initialState:H});function W(e){return H.safeParse(e).success}function G(e){H.parse(e)}function K(e){return U.safeParse(e).success}function q(e){U.parse(e)}var J={setProcessorNameOperation(e,t,n){let r=t.input.name.trim();if(r===``)throw Error(`Processor name cannot be empty`);e.name=r},setProcessorTypeOperation(e,t,n){let r=t.input.type.trim();if(r===``)throw Error(`Processor type cannot be empty`);e.type=r},addDocumentTypeOperation(e,t,n){if(e.documentTypes.find(e=>e.id===t.input.id))throw Error(`Document type with id "${t.input.id}" already exists`);e.documentTypes.push({id:t.input.id,documentType:t.input.documentType})},removeDocumentTypeOperation(e,t,n){e.documentTypes=e.documentTypes.filter(e=>e.id!==t.input.id)},setProcessorStatusOperation(e,t,n){e.status=t.input.status},addProcessorAppOperation(e,t){let{processorApp:n}=t.input;if(!g.includes(n))throw Error(`${n} is not a valid processor app. Must be one of ${g.join(`, `)}.`);e.processorApps=[...new Set([...e.processorApps,n])]},removeProcessorAppOperation(e,t){let{processorApp:n}=t.input;e.processorApps=e.processorApps.filter(e=>e!==n)}},Y=r((e,t,n)=>{if(u(t))return e;switch(t.type){case`SET_PROCESSOR_NAME`:k().parse(t.input),J.setProcessorNameOperation(e[t.scope],t,n);break;case`SET_PROCESSOR_TYPE`:j().parse(t.input),J.setProcessorTypeOperation(e[t.scope],t,n);break;case`ADD_DOCUMENT_TYPE`:C().parse(t.input),J.addDocumentTypeOperation(e[t.scope],t,n);break;case`REMOVE_DOCUMENT_TYPE`:D().parse(t.input),J.removeDocumentTypeOperation(e[t.scope],t,n);break;case`ADD_PROCESSOR_APP`:w().parse(t.input),J.addProcessorAppOperation(e[t.scope],t,n);break;case`REMOVE_PROCESSOR_APP`:O().parse(t.input),J.removeProcessorAppOperation(e[t.scope],t,n);break;case`SET_PROCESSOR_STATUS`:A().parse(t.input),J.setProcessorStatusOperation(e[t.scope],t,n);break;default:return e}}),X={name:``,type:``,documentTypes:[],status:`DRAFT`,processorApps:[]},Z={},Q={fileExtension:`.phdm`,createState(e){return{...m(),global:{...X,...e?.global},local:{...Z,...e?.local}}},createDocument(e){let t=n(Q.createState,e);return t.header.documentType=B,t.header.id=_(),t},saveToFileHandle(e,n){return t(e,n)},loadFromInput(e){return p(e,Y)},isStateOfType(e){return W(e)},assertIsStateOfType(e){return G(e)},isDocumentOfType(e){return K(e)},assertIsDocumentOfType(e){return q(e)}},$=y({}),ee={...e,...M},te={...Q,...$};export{Y as a,N as c,te as d,b as i,z as l,F as n,I as o,L as r,R as s,ee as t,P as u};
//# sourceMappingURL=processor-module-CkuQiq7B-COkXWoSC.js.map