"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@viamedici-spc/fp-ts-extensions"),Ve=require("fp-ts/Refinement"),u=require("ts-pattern"),b=require("xstate"),x=require("fp-ts/Option"),Wt=require("fp-ts/es6/function");require("fp-ts/es6/pipeable");require("fp-ts/es6/ReadonlyArray");require("fp-ts/es6/ReadonlyRecord");require("fp-ts/es6/Option");require("fp-ts/es6/Either");const We=require("spark-md5"),je=require("fp-ts/Show"),Ue=require("fp-ts/Endomorphism"),Le=require("fast-equals"),_e=require("fp-ts/Semigroup"),k=require("memize"),He=require("fp-ts/Apply"),Ht=require("p-defer"),It=require("dyna-guid"),ze=require("fp-ts/ReadonlyTuple"),zt=require("@morphic-ts/batteries/lib/summoner-ESBAST");function st(t){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(i,n,o.get?o:{enumerable:!0,get:()=>t[n]})}}return i.default=t,Object.freeze(i)}const N=st(je),$e=st(Ue),L=st(_e),Ge=st(ze);var l=(t=>(t.RequestTimeout="RequestTimeout",t.RequestFailure="RequestFailure",t.SerializationError="SerializationError",t.MissingTenantIdClaim="MissingTenantIdClaim",t.MissingSessionIdClaim="MissingSessionIdClaim",t.TenantAccessForbidden="TenantAccessForbidden",t.SessionIdInvalid="SessionIdInvalid",t.AuthenticationFailure="AuthenticationFailure",t.SideLoadingForbidden="SideLoadingForbidden",t.UsageRuleRestriction="UsageRuleRestriction",t.ConfigurationModelInvalid="ConfigurationModelInvalid",t.SolutionNotFeasible="SolutionNotFeasible",t.ConfigurationModelNotFound="ConfigurationModelNotFound",t.SolverInitializationFailure="SolverInitializationFailure",t.ConfigurationModelLoadFailure="ConfigurationModelLoadFailure",t.ConfigurationInitializationFailure="ConfigurationInitializationFailure",t.SolverPoolInitializationFailure="SolverPoolInitializationFailure",t.SetDecisionConflict="SetDecisionConflict",t.SolveOperationTimeout="SolveOperationTimeout",t.ExplainConflict="ExplainConflict",t.ExplainFailure="ExplainFailure",t.SnapshotInvalid="SnapshotInvalid",t.SnapshotNotFound="SnapshotNotFound",t.ConfigurationModelNotFeasible="ConfigurationModelNotFeasible",t.MakeManyDecisionsConflict="MakeManyDecisionsConflict",t.SpecifiedDeploymentForbidden="SpecifiedDeploymentForbidden",t.AttributeNotFound="AttributeNotFound",t.ChoiceAttributeNotFound="ChoiceAttributeNotFound",t.ComponentAttributeNotFound="ComponentAttributeNotFound",t.NumericAttributeNotFound="NumericAttributeNotFound",t.BooleanAttributeNotFound="BooleanAttributeNotFound",t.ChoiceValueNotFound="ChoiceValueNotFound",t.NumericDecisionOutOfRange="NumericDecisionOutOfRange",t.ConflictWithConsequence="ConflictWithConsequence",t.DecisionsToRespectInvalid="DecisionsToRespectInvalid",t.SessionNotFound="SessionNotFound",t.ServerError="ServerError",t.ConnectionError="ConnectionError",t.TaskCancelled="TaskCancelled",t.SessionClosed="SessionClosed",t.StoredConfigurationInvalid="StoredConfigurationInvalid",t))(l||{}),q=(t=>(t.whyIsNotSatisfied="why-is-not-satisfied",t.whyIsStateNotPossible="why-is-state-not-possible",t))(q||{}),S=(t=>(t.choiceValue="choice-value",t.component="component",t.boolean="boolean",t.numeric="numeric",t.configuration="configuration",t.attribute="attribute",t))(S||{}),B=(t=>(t.all="all",t.none="none",t.specific="specific",t))(B||{}),_=(t=>(t.Channel="Channel",t.Package="Package",t))(_||{}),r=(t=>(t.Boolean="Boolean",t.Numeric="Numeric",t.Choice="Choice",t.Component="Component",t))(r||{}),I=(t=>(t.Included="Included",t.Excluded="Excluded",t))(I||{}),R=(t=>(t.Included="Included",t.Excluded="Excluded",t))(R||{}),E=(t=>(t.Implicit="Implicit",t.Explicit="Explicit",t))(E||{}),V=(t=>(t.Mandatory="Mandatory",t.Optional="Optional",t))(V||{}),H=(t=>(t.Always="Always",t.Optional="Optional",t))(H||{});const Qe=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),Ct=t=>t.type===r.Boolean,At=t=>t.type===r.Choice,qt=t=>t.type===r.Numeric,Rt=t=>t.type===r.Component,Ke=Object.freeze(Object.defineProperty({__proto__:null,booleanAttributeRefinement:Ct,choiceAttributeRefinement:At,componentAttributeRefinement:Rt,numericAttributeRefinement:qt},Symbol.toStringTag,{value:"Module"}));function T(t){const n=[...t.sharedConfigurationModelId?["shared",t.sharedConfigurationModelId]:["root"],...t.componentPath??[],t.localId];return e.pipe(n,e.RA.map(o=>o.replace("::","|::|")),o=>o.join("::"))}function Je(t,i,n){return e.pipe(t,e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([o,s])=>s),e.RA.filter(o=>{if(o.id.sharedConfigurationModelId!=i.sharedConfigurationModelId)return!1;const s=[...i.componentPath??[],i.localId],a=e.pipe(o.id.componentPath??[],n?e.RA.takeLeft(s.length):e.identity);return e.RA.getEq(e.Str.Eq).equals(s,a)}))}function Xe(t,i,n){return e.pipe(t,e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([o,s])=>s),e.RA.filter(o=>o.id.sharedConfigurationModelId==i&&(n||e.RA.isEmpty(o.id.componentPath??[]))))}function Ye(t){return e.pipe(t,e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([i,n])=>n),e.RA.filter(i=>i.id.sharedConfigurationModelId==null&&e.RA.isEmpty(i.id.componentPath??[])))}function rt(t){return i=>e.pipe(i.attributes,e.RM.filter(t),e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([n,o])=>o))}function Ze(t){return rt(At)(t)}function ti(t){return rt(Rt)(t)}function ei(t){return rt(qt)(t)}function ii(t){return rt(Ct)(t)}function G(t,i,n){const o=typeof i=="string"?i:T(i),s=t.attributes.get(o);return s&&(n??Ve.id)(s)?s:void 0}function $t(t,i){return G(t,i,At)}function ni(t,i,n){const o=$t(t,i);return((o==null?void 0:o.values)??e.RM.empty).get(n)}function oi(t,i){return G(t,i,qt)}function si(t,i){return G(t,i,Ct)}function ri(t,i){return G(t,i,Rt)}const ai=Object.freeze(Object.defineProperty({__proto__:null,getAttribute:G,getAttributesOfComponentAttribute:Je,getAttributesOfRootConfigurationModel:Ye,getAttributesOfSharedConfigurationModel:Xe,getBooleanAttribute:si,getBooleanAttributes:ii,getChoiceAttribute:$t,getChoiceAttributes:Ze,getChoiceValue:ni,getComponentAttribute:ri,getComponentAttributes:ti,getNumericAttribute:oi,getNumericAttributes:ei},Symbol.toStringTag,{value:"Module"}));function Dt(t){return t.possibleDecisionStates.includes(I.Included)}function Gt(t){return!Dt(t)}const ci=Object.freeze(Object.defineProperty({__proto__:null,isAllowed:Dt,isBlocked:Gt},Symbol.toStringTag,{value:"Module"}));function ui(t){return u.match(t).with({type:r.Choice},i=>i.cardinality.lowerBound>0).with({type:r.Boolean},i=>i.selection===V.Mandatory).with({type:r.Numeric},i=>i.selection===V.Mandatory).with({type:r.Component},i=>i.inclusion===H.Optional&&i.selection===V.Mandatory).exhaustive()}function li(t){return t.cardinality.upperBound>1}function di(t){return e.pipe(t.values,e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([i,n])=>n),e.RA.filter(Dt))}function pi(t){return e.pipe(t.values,e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([i,n])=>n),e.RA.filter(Gt))}function hi(t){return e.pipe(t.values,e.RM.filter(i=>{var n;return((n=i.decision)==null?void 0:n.state)===I.Included}),e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([i,n])=>n))}const mi=Object.freeze(Object.defineProperty({__proto__:null,getAllowedChoiceValues:di,getBlockedChoiceValues:pi,getIncludedChoiceValues:hi,isChoiceAttributeMultiSelect:li,isMandatory:ui},Symbol.toStringTag,{value:"Module"})),xt={whyIsNotSatisfied:{configuration:{question:q.whyIsNotSatisfied,subject:S.configuration},attribute:t=>({question:q.whyIsNotSatisfied,subject:S.attribute,attributeId:t})},whyIsStateNotPossible:{choice:t=>({choiceValue:i=>({state:n=>({question:q.whyIsStateNotPossible,subject:S.choiceValue,attributeId:t,choiceValueId:i,state:n})})}),boolean:t=>({state:i=>({question:q.whyIsStateNotPossible,subject:S.boolean,attributeId:t,state:i})}),numeric:t=>({state:i=>({question:q.whyIsStateNotPossible,subject:S.numeric,attributeId:t,state:i})}),component:t=>({state:i=>({question:q.whyIsStateNotPossible,subject:S.component,attributeId:t,state:i})})}},fi=Object.freeze(Object.defineProperty({__proto__:null,explainQuestionBuilder:xt},Symbol.toStringTag,{value:"Module"})),yi=t=>t.attributeType===r.Boolean,bi=t=>t.attributeType===r.Numeric,gi=t=>t.attributeType===r.Component,Si=t=>t.attributeType===r.Choice,Qt=t=>t.kind===E.Explicit,Kt=t=>t.kind===E.Implicit,Ei=Object.freeze(Object.defineProperty({__proto__:null,collectedBooleanDecisionRefinement:yi,collectedChoiceDecisionRefinement:Si,collectedComponentDecisionRefinement:gi,collectedExplicitDecisionRefinement:Qt,collectedImplicitDecisionRefinement:Kt,collectedNumericDecisionRefinement:bi},Symbol.toStringTag,{value:"Module"}));var P=(t=>(t.Included="Included",t.Excluded="Excluded",t))(P||{}),gt=(t=>(t.Mandatory="Mandatory",t.Optional="Optional",t))(gt||{}),St=(t=>(t.Always="Always",t.Optional="Optional",t))(St||{}),Et=(t=>(t.Implicit="Implicit",t.Explicit="Explicit",t))(Et||{}),C=(t=>(t.Included="Included",t.Excluded="Excluded",t.Undefined="Undefined",t))(C||{});class wi{constructor(i={}){this.baseUrl="https://spc.cloud.ceventis.de/hca/api/engine",this.securityData=null,this.abortControllers=new Map,this.customFetch=(...n)=>fetch(...n),this.baseApiParams={credentials:"same-origin",headers:{},redirect:"follow",referrerPolicy:"no-referrer"},this.setSecurityData=n=>{this.securityData=n},this.contentFormatters={"application/json":n=>n!==null&&(typeof n=="object"||typeof n=="string")?JSON.stringify(n):n,"text/plain":n=>n!==null&&typeof n!="string"?JSON.stringify(n):n,"multipart/form-data":n=>Object.keys(n||{}).reduce((o,s)=>{const a=n[s];return o.append(s,a instanceof Blob?a:typeof a=="object"&&a!==null?JSON.stringify(a):`${a}`),o},new FormData),"application/x-www-form-urlencoded":n=>this.toQueryString(n)},this.createAbortSignal=n=>{if(this.abortControllers.has(n)){const s=this.abortControllers.get(n);return s?s.signal:void 0}const o=new AbortController;return this.abortControllers.set(n,o),o.signal},this.abortRequest=n=>{const o=this.abortControllers.get(n);o&&(o.abort(),this.abortControllers.delete(n))},this.request=async({body:n,secure:o,path:s,type:a,query:c,format:p,baseUrl:d,cancelToken:h,...w})=>{const A=(typeof o=="boolean"?o:this.baseApiParams.secure)&&this.securityWorker&&await this.securityWorker(this.securityData)||{},J=this.mergeRequestParams(w,A),Ft=c&&this.toQueryString(c),Te=this.contentFormatters[a||"application/json"],Tt=p||J.format;return this.customFetch(`${d||this.baseUrl||""}${s}${Ft?`?${Ft}`:""}`,{...J,headers:{...J.headers||{},...a&&a!=="multipart/form-data"?{"Content-Type":a}:{}},signal:(h?this.createAbortSignal(h):J.signal)||null,body:typeof n>"u"||n===null?null:Te(n)}).then(async ht=>{const M=ht;M.data=null,M.error=null;const Vt=Tt?await ht[Tt]().then(X=>(M.ok?M.data=X:M.error=X,M)).catch(X=>(M.error=X,M)):M;if(h&&this.abortControllers.delete(h),!ht.ok)throw Vt;return Vt})},Object.assign(this,i)}encodeQueryParam(i,n){return`${encodeURIComponent(i)}=${encodeURIComponent(typeof n=="number"?n:`${n}`)}`}addQueryParam(i,n){return this.encodeQueryParam(n,i[n])}addArrayQueryParam(i,n){return i[n].map(s=>this.encodeQueryParam(n,s)).join("&")}toQueryString(i){const n=i||{};return Object.keys(n).filter(s=>typeof n[s]<"u").map(s=>Array.isArray(n[s])?this.addArrayQueryParam(n,s):this.addQueryParam(n,s)).join("&")}addQueryParams(i){const n=this.toQueryString(i);return n?`?${n}`:""}mergeRequestParams(i,n){return{...this.baseApiParams,...i,...n||{},headers:{...this.baseApiParams.headers||{},...i.headers||{},...n&&n.headers||{}}}}}/** * @title Viamedici.Spc.Engine.ConfigurationEngine.RestApi.Service * @version v2 * @license © 2024 Viamedici - All rights reserved (https://viamedici.de) * @termsOfService None * @baseUrl https://spc.cloud.ceventis.de/hca/api/engine * @contact Viamedici Software GmbH (https://viamedici.de) */class Jt extends wi{constructor(){super(...arguments),this.consequence={consequenceGet:(i={})=>this.request({path:"/v2/session/configuration/consequence",method:"GET",secure:!0,format:"json",...i})},this.decision={decisionPutDecision:(i,n={})=>this.request({path:"/v2/session/configuration/decision",method:"PUT",body:i,secure:!0,type:"application/json",format:"json",...n}),decisionGetAllDecisions:(i={})=>this.request({path:"/v2/session/configuration/decision",method:"GET",secure:!0,format:"json",...i}),decisionPutMany:(i,n={})=>this.request({path:"/v2/session/configuration/decision/many",method:"PUT",body:i,secure:!0,type:"application/json",format:"json",...n})},this.explain={explainWhyNotSatisfied:(i,n={})=>this.request({path:"/v2/session/configuration/consequence/explain/why-not-satisfied",method:"POST",body:i,secure:!0,type:"application/json",format:"json",...n}),explainWhyNotSatisfiedDecisions:(i,n={})=>this.request({path:"/v2/session/configuration/consequence/explain/why-not-satisfied/answer/decisions",method:"POST",body:i,secure:!0,type:"application/json",format:"json",...n}),explainWhyNotSatisfiedRules:(i,n={})=>this.request({path:"/v2/session/configuration/consequence/explain/why-not-satisfied/answer/constraints",method:"POST",body:i,secure:!0,type:"application/json",format:"json",...n}),explainWhyStateNotPossible:(i,n={})=>this.request({path:"/v2/session/configuration/consequence/explain/why-state-not-possible",method:"POST",body:i,secure:!0,type:"application/json",format:"json",...n}),explainWhyStateNotPossibleDecisions:(i,n={})=>this.request({path:"/v2/session/configuration/consequence/explain/why-state-not-possible/answer/decisions",method:"POST",body:i,secure:!0,type:"application/json",format:"json",...n}),explainWhyStateNotPossibleRules:(i,n={})=>this.request({path:"/v2/session/configuration/consequence/explain/why-state-not-possible/answer/constraints",method:"POST",body:i,secure:!0,type:"application/json",format:"json",...n})},this.meta={metaGetConfigurationModel:(i={})=>this.request({path:"/v2/session/configuration/meta/configuration-model",method:"GET",secure:!0,format:"json",...i}),metaGet:(i={})=>this.request({path:"/v2/session/configuration/meta",method:"GET",secure:!0,format:"json",...i})},this.session={sessionPost:(i,n={})=>this.request({path:"/v2/session",method:"POST",body:i,secure:!0,type:"application/json",format:"json",...n}),sessionDelete:(i,n={})=>this.request({path:`/v2/session/${i}`,method:"DELETE",secure:!0,...n}),sessionClose:(i,n={})=>this.request({path:"/v2/session/close",method:"POST",body:i,secure:!0,type:"application/json",...n})}}}const Ii="https://spc.cloud.ceventis.de/hca/api/engine",jt=new Map,Ut=new Map;function Q(t){const i=t??Ii;let n=jt.get(i);return n||(n=new Jt({baseUrl:i}),jt.set(i,n)),n}function Ci(t){const i=(...o)=>typeof o[0]=="string"?fetch(t,o[1]):fetch(...o);let n=Ut.get(t);return n||(n=new Jt({customFetch:i}),Ut.set(t,n)),n.session.sessionPost}function D(t){return{sharedConfigurationModelId:t.sharedConfigurationModelId,componentPath:t.componentPath!=null?e.RA.toArray(t.componentPath):void 0,localId:t.localId}}function Xt(t){return{type:"Choice",attributeId:D(t.attributeId),choiceValueId:t.choiceValueId,state:u.match(t.state).with(u.P.nullish,()=>C.Undefined).with(I.Included,()=>C.Included).with(I.Excluded,()=>C.Excluded).exhaustive()}}function Yt(t){return{type:"Component",attributeId:D(t.attributeId),state:u.match(t.state).with(u.P.nullish,()=>C.Undefined).with(R.Included,()=>C.Included).with(R.Excluded,()=>C.Excluded).exhaustive()}}function Zt(t){return{type:"Numeric",attributeId:D(t.attributeId),state:t.state}}function te(t){return{type:"Boolean",attributeId:D(t.attributeId),state:t.state}}function Ai(t){return u.match(t).with({type:r.Choice},Xt).with({type:r.Component},Yt).with({type:r.Boolean},te).with({type:r.Numeric},Zt).exhaustive()}function qi(t){const i=u.match(t.configurationModelSource).returnType().with({type:_.Channel},a=>({type:"Channel",deploymentName:a.deploymentName,channel:a.channel})).with({type:_.Package},a=>({type:"Package",configurationModelPackage:a.configurationModelPackage})).exhaustive(),n=()=>{var c;const a=(c=t.allowedInExplain)!=null&&c.rules?u.match(t.allowedInExplain.rules).returnType().with({type:B.all},()=>({type:"AllowedRulesAll"})).with({type:B.none},()=>({type:"AllowedRulesNone"})).with({type:B.specific},p=>({type:"AllowedRulesSpecific",rules:e.pipe(p.rules,e.RA.map(d=>({configurationModelId:d.configurationModelId,localId:d.localId})),e.RA.toArray)})).exhaustive():void 0;if(a)return{rules:a}},o=t.attributeRelations?e.pipe(t.attributeRelations,e.RA.map(a=>({attributeId:D(a.attributeId),decisions:e.pipe(a.decisions,e.RA.map(D),e.RA.toArray)})),e.RA.toArray):void 0,s=t.usageRuleParameters?t.usageRuleParameters:void 0;return{configurationModelSource:i,allowedInExplain:n(),attributeRelations:o,usageRuleParameters:s}}function Ri(t,i){const n=(d,h)=>e.pipe(t,e.RA.filter(d),e.RA.map(h),e.RA.toArray),o=n(d=>d.type===r.Boolean,te),s=n(d=>d.type===r.Numeric,Zt),a=n(d=>d.type===r.Component,Yt),c=n(d=>d.type===r.Choice,Xt),p=u.match(i).with({type:"DropExistingDecisions"},d=>({type:"DropExistingDecisions",conflictResolution:u.match(d.conflictHandling).with({type:"Automatic"},()=>({type:"Automatic"})).with({type:"Manual"},h=>({type:"Manual",includeConstraintsInConflictExplanation:h.includeConstraintsInConflictExplanation})).exhaustive()})).with({type:"KeepExistingDecisions"},()=>({type:"KeepExistingDecisions"})).exhaustive();return{booleanDecisions:o,componentDecisions:a,numericDecisions:s,choiceDecisions:c,mode:p}}function Di(t){return u.match(t).returnType().with({subject:S.configuration},()=>({type:"Configuration"})).with({subject:S.attribute},i=>({type:"Attribute",attributeId:D(i.attributeId)})).exhaustive()}function xi(t){return u.match(t).returnType().with({subject:S.boolean},i=>({type:"Boolean",attributeId:D(i.attributeId),state:i.state})).with({subject:S.numeric},i=>({type:"Numeric",attributeId:D(i.attributeId),state:i.state})).with({subject:S.component},i=>({type:"Component",attributeId:D(i.attributeId),state:u.match(i.state).with(R.Included,()=>P.Included).with(R.Excluded,()=>P.Excluded).exhaustive()})).with({subject:S.choiceValue},i=>({type:"ChoiceValue",attributeId:D(i.attributeId),choiceValueId:i.choiceValueId,state:u.match(i.state).with(I.Included,()=>P.Included).with(I.Excluded,()=>P.Excluded).exhaustive()})).exhaustive()}const Y={type:l.ServerError};function vi(t){return u.match(t).returnType().with({type:"ConfigurationModelNotFeasible"},Ni).with({type:"SpecifiedDeploymentForbidden"},Mi).with({type:"AttributeNotFound"},ki).with({type:"ChoiceAttributeNotFound"},Pi).with({type:"ComponentAttributeNotFound"},Bi).with({type:"NumericAttributeNotFound"},Oi).with({type:"BooleanAttributeNotFound"},Fi).with({type:"ChoiceValueNotFound"},Ti).with({type:"NumericDecisionOutOfRange"},Vi).with({type:"ConflictWithConsequence"},Wi).with({type:"DecisionsToRespectInvalid"},ji).with({type:"SessionNotFound"},Ui).with({type:"PutManyDecisionsConflict"},()=>Y).with({type:"AssignedChannelNotFound"},()=>Y).with({type:"InternalServerError"},()=>Y).with({type:"RequestTimeout"},i=>f(i,l.RequestTimeout)).with({type:"RequestFailure"},i=>f(i,l.RequestFailure)).with({type:"SerializationError"},i=>f(i,l.SerializationError)).with({type:"MissingTenantIdClaim"},i=>f(i,l.MissingTenantIdClaim)).with({type:"MissingSessionIdClaim"},i=>f(i,l.MissingSessionIdClaim)).with({type:"TenantAccessForbidden"},i=>f(i,l.TenantAccessForbidden)).with({type:"SessionIdInvalid"},i=>f(i,l.SessionIdInvalid)).with({type:"AuthenticationFailure"},i=>f(i,l.AuthenticationFailure)).with({type:"SideLoadingForbidden"},i=>f(i,l.SideLoadingForbidden)).with({type:"UsageRuleRestriction"},i=>f(i,l.UsageRuleRestriction)).with({type:"ConfigurationModelInvalid"},i=>f(i,l.ConfigurationModelInvalid)).with({type:"SolutionNotFeasible"},i=>f(i,l.SolutionNotFeasible)).with({type:"ConfigurationModelNotFound"},i=>f(i,l.ConfigurationModelNotFound)).with({type:"SolverInitializationFailure"},i=>f(i,l.SolverInitializationFailure)).with({type:"ConfigurationModelLoadFailure"},i=>f(i,l.ConfigurationModelLoadFailure)).with({type:"ConfigurationInitializationFailure"},i=>f(i,l.ConfigurationInitializationFailure)).with({type:"SolverPoolInitializationFailure"},i=>f(i,l.SolverPoolInitializationFailure)).with({type:"SetDecisionConflict"},i=>f(i,l.SetDecisionConflict)).with({type:"SolveOperationTimeout"},i=>f(i,l.SolveOperationTimeout)).with({type:"ExplainConflict"},i=>f(i,l.ExplainConflict)).with({type:"ExplainFailure"},i=>f(i,l.ExplainFailure)).with({type:"SnapshotInvalid"},i=>f(i,l.SnapshotInvalid)).with({type:"SnapshotNotFound"},i=>f(i,l.SnapshotNotFound)).otherwise(()=>Y)}function f(t,i){return{...t,type:i}}function Ni(t){return{...t,type:l.ConfigurationModelNotFeasible,constraintExplanations:e.pipe(t.constraintExplanations??[],e.RA.map(vt))}}function Mi(t){return{...t,type:l.SpecifiedDeploymentForbidden}}function ki(t){return{...t,type:l.AttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Pi(t){return{...t,type:l.ChoiceAttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Bi(t){return{...t,type:l.ComponentAttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Oi(t){return{...t,type:l.NumericAttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Fi(t){return{...t,type:l.BooleanAttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Ti(t){const{globalChoiceValueId:i,...n}=t;return{...n,type:l.ChoiceValueNotFound,globalAttributeId:y(i.attributeId),choiceValueId:i.choiceValueId}}function Vi(t){return{...t,type:l.NumericDecisionOutOfRange,globalAttributeId:y(t.globalAttributeId)}}function Wi(t){return{...t,type:l.ConflictWithConsequence,globalAttributeId:y(t.globalAttributeId)}}function ji(t){return{...t,type:l.DecisionsToRespectInvalid,globalAttributeId:y(t.globalAttributeId)}}function Ui(){return{type:l.SessionNotFound}}function Li(t){const i=e.pipe(t.causedByBooleanDecisions,e.RA.map(a=>({type:r.Boolean,attributeId:y(a.attributeId),state:a.state}))),n=e.pipe(t.causedByNumericDecisions,e.RA.map(a=>({type:r.Numeric,attributeId:y(a.attributeId),state:a.state}))),o=e.pipe(t.causedByComponentDecisions,e.RA.map(a=>({type:r.Component,attributeId:y(a.attributeId),state:ee(a.state)}))),s=e.pipe(t.causedByChoiceDecisions,e.RA.map(a=>({type:r.Choice,attributeId:y(a.attributeId),choiceValueId:a.choiceValueId,state:ie(a.state)})));return{causedByBooleanDecisions:i,causedByNumericDecisions:n,causedByComponentDecisions:o,causedByChoiceValueDecisions:s}}function vt(t){const i=e.pipe(t.causedByCardinalities,e.RA.map(o=>y(o.attributeId))),n=e.pipe(t.causedByRules,e.RA.map(o=>_i(o.constraintId)));return{causedByCardinalities:i,causedByRules:n}}function y(t){const i=t.sharedConfigurationModelId!=null?t.sharedConfigurationModelId:void 0,n=t.componentPath!=null&&e.RA.isNonEmpty(t.componentPath)?t.componentPath:void 0;return{localId:t.localId,componentPath:n,sharedConfigurationModelId:i}}function _i(t){return{localId:t.localId,configurationModelId:t.configurationModelId}}function ee(t){return u.match(t).with(P.Included,()=>R.Included).with(P.Excluded,()=>R.Excluded).exhaustive()}function ie(t){return u.match(t).with(P.Included,()=>I.Included).with(P.Excluded,()=>I.Excluded).exhaustive()}function at(t){return u.match(t).with(Et.Explicit,()=>E.Explicit).with(Et.Implicit,()=>E.Implicit).exhaustive()}function ne({state:t,kind:i}){return t!=null?{state:t,kind:at(i)}:null}function oe({state:t,kind:i}){return t!=null?{state:t,kind:at(i)}:null}function se({state:t,kind:i}){return t===C.Included||t===C.Excluded?{state:u.match(t).with(C.Included,()=>R.Included).with(C.Excluded,()=>R.Excluded).exhaustive(),kind:at(i)}:null}function re({state:t,kind:i}){return t===C.Included||t===C.Excluded?{state:u.match(t).with(C.Included,()=>I.Included).with(C.Excluded,()=>I.Excluded).exhaustive(),kind:at(i)}:null}function mt(t){return u.match(t).with(gt.Mandatory,()=>V.Mandatory).with(gt.Optional,()=>V.Optional).exhaustive()}function Hi(t){return u.match(t).with(St.Always,()=>H.Always).with(St.Optional,()=>H.Optional).exhaustive()}function zi(t){const i=e.pipe(t.componentDecisions,e.RA.map(a=>{var c;return{type:r.Component,attributeId:y(a.attributeId),state:(c=se(a))==null?void 0:c.state}})),n=e.pipe(t.booleanDecisions,e.RA.map(a=>{var c;return{type:r.Boolean,attributeId:y(a.attributeId),state:(c=ne(a))==null?void 0:c.state}})),o=e.pipe(t.numericDecisions,e.RA.map(a=>{var c;return{type:r.Numeric,attributeId:y(a.attributeId),state:(c=oe(a))==null?void 0:c.state}})),s=e.pipe(t.choiceValueDecisions,e.RA.map(a=>{var c;return{type:r.Choice,attributeId:y(a.attributeId),choiceValueId:a.choiceValueId,state:(c=re(a))==null?void 0:c.state}}));return e.pipe(s,e.RA.concat(i),e.RA.concat(o),e.RA.concat(n))}var ae=function(t,i){return{get:t,set:i}},$i=function(){return ae(Wt.identity,Wt.constant)},Gi=function(t){return function(i){return ae(function(n){return i.get(n)[t]},function(n){return function(o){var s,a=i.get(o);return n===a[t]?o:i.set(Object.assign({},a,(s={},s[t]=n,s)))(o)}})}},Qi=$i,Ki=function(t){return function(i){return function(n){var o=i.get(n),s=t(o);return o===s?n:i.set(s)(n)}}},Ji=Gi;const Xi=t=>t.hash!=null;function O(t){const i=new WeakMap;return{show:n=>{const o=i.get(n);if(o!=null)return o;const s=t.show(n);return i.set(n,s),s}}}const Yi=e.RA.getShow(e.Str.Show),ct=t=>({show:i=>i==null?"":t.show(i)}),Zi={show:t=>t!=null&&e.RA.isNonEmpty(t)?Yi.show(t):""},tn=O(N.struct({localId:e.Str.Show,componentPath:Zi,sharedConfigurationModelId:ct(e.Str.Show)})),en=e.Str.Show,nn=e.pipe(N.struct({localId:e.Str.Show,configurationModel:e.Str.Show}),O,ct),F=t=>e.pipe(N.struct({kind:e.Str.Show,state:t}),O,ct),ut={id:tn,key:en,type:e.Str.Show,sourceId:nn,isSatisfied:e.Bool.Show,canContributeToConfigurationSatisfaction:e.Bool.Show},on=N.struct({...ut,decision:F(e.Bool.Show),nonOptimisticDecision:F(e.Bool.Show),possibleDecisionStates:O(e.RA.getShow(e.Bool.Show)),selection:e.Str.Show}),sn=N.struct({...ut,decision:F(e.Num.Show),nonOptimisticDecision:F(e.Num.Show),selection:e.Str.Show,range:O(N.struct({max:e.Num.Show,min:e.Num.Show})),decimalPlaces:e.Num.Show}),rn=N.struct({...ut,decision:F(e.Str.Show),nonOptimisticDecision:F(e.Str.Show),possibleDecisionStates:O(e.RA.getShow(e.Str.Show)),selection:ct(e.Str.Show),inclusion:e.Str.Show}),an=N.struct({...ut,cardinality:O(N.struct({upperBound:e.Num.Show,lowerBound:e.Num.Show})),values:e.RM.getShow(e.Str.Show,N.struct({id:e.Str.Show,decision:F(e.Str.Show),nonOptimisticDecision:F(e.Str.Show),possibleDecisionStates:O(e.RA.getShow(e.Str.Show))}))}),cn={show:t=>u.match(t).with({type:r.Choice},an.show).with({type:r.Component},rn.show).with({type:r.Boolean},on.show).with({type:r.Numeric},sn.show).exhaustive()},un=e.flow(cn.show,e.I.map(t=>We.hash(t)));function ln(t){return{...t,hash:un(t)}}function Nt(t){return e.MO.concatAll($e.getMonoid())(t)}const m=e.Str.Eq,g=e.Eq.struct({localId:e.Str.Eq,componentPath:e.pipe(e.RA.getEq(e.Str.Eq),e.Eq.contramap(t=>t??[])),sharedConfigurationModelId:e.Eq.eqNullable(e.Str.Eq)}),Mt=e.Eq.struct({localId:e.Str.Eq,configurationModelId:e.Str.Eq}),dn=e.Eq.struct({type:e.Str.Eq,includeConstraintsInConflictExplanation:e.Bool.Eq}),pn=e.Eq.struct({type:e.Str.Eq}),hn=e.Eq.union().with(t=>t.type==="Automatic",pn).with(t=>t.type==="Manual",dn),mn=e.Eq.struct({type:e.Str.Eq,conflictHandling:hn}),fn=e.Eq.struct({type:e.Str.Eq}),yn=e.Eq.union().with(t=>t.type==="DropExistingDecisions",mn).with(t=>t.type==="KeepExistingDecisions",fn),bn=e.Eq.struct({type:e.Str.Eq,attributeId:g,state:e.Eq.eqNullable(e.Bool.Eq)}),gn=e.Eq.struct({type:e.Str.Eq,attributeId:g,state:e.Eq.eqNullable(e.Num.Eq)}),Sn=e.Eq.struct({type:e.Str.Eq,attributeId:g,state:e.Eq.eqNullable(e.Str.Eq)}),En=e.Eq.struct({type:e.Str.Eq,attributeId:g,choiceValueId:e.Str.Eq,state:e.Eq.eqNullable(e.Str.Eq)}),kt=e.Eq.union().with(t=>t.type===r.Boolean,bn).with(t=>t.type===r.Numeric,gn).with(t=>t.type===r.Component,Sn).with(t=>t.type===r.Choice,En),ce=e.pipe(e.Eq.struct({attributeId:g,choiceValueId:e.O.getEq(e.Str.Eq)}),e.Eq.contramap(t=>u.match(t).with({type:r.Choice},i=>({attributeId:i.attributeId,choiceValueId:e.some(i.choiceValueId)})).otherwise(i=>({attributeId:i.attributeId,choiceValueId:x.none})))),wn=e.Eq.struct({mode:yn,decisions:e.RA.getUnsortedArrayEq(kt)}),ue=e.Eq.struct({causedByDecisions:e.RA.getUnsortedArrayEq(kt),solution:wn}),le=e.Eq.struct({causedByCardinalities:e.RA.getUnsortedArrayEq(g),causedByRules:e.RA.getUnsortedArrayEq(Mt)}),In=e.Eq.struct({key:m,sourceId:e.Eq.struct({configurationModel:e.Str.Eq,localId:e.Str.Eq})}),et=e.Eq.eqNullable(e.Eq.struct({state:e.Bool.Eq,kind:e.Str.Eq})),Cn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,decision:et,nonOptimisticDecision:et}),it=e.Eq.eqNullable(e.Eq.struct({state:e.Num.Eq,kind:e.Str.Eq})),An=e.Eq.struct({type:e.Str.Eq,id:g,key:m,decision:it,nonOptimisticDecision:it}),nt=e.Eq.eqNullable(e.Eq.struct({state:e.Str.Eq,kind:e.Str.Eq})),qn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,decision:nt,nonOptimisticDecision:nt}),ot=e.Eq.eqNullable(e.Eq.struct({state:e.Str.Eq,kind:e.Str.Eq})),Rn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,values:e.RA.getUnsortedArrayEq(e.Eq.struct({id:e.Str.Eq,decision:ot,nonOptimisticDecision:ot}))}),Dn=e.Eq.union().with(t=>t.type===r.Boolean,Cn).with(t=>t.type===r.Numeric,An).with(t=>t.type===r.Component,qn).with(t=>t.type===r.Choice,Rn),xn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Bool.Eq),selection:e.Str.Eq,isSatisfied:e.Bool.Eq}),vn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,range:e.Eq.struct({max:e.Num.Eq,min:e.Num.Eq}),isSatisfied:e.Bool.Eq,selection:e.Str.Eq,decimalPlaces:e.Num.Eq}),Nn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Str.Eq),isSatisfied:e.Bool.Eq,inclusion:e.Str.Eq,selection:e.Eq.eqNullable(e.Str.Eq)}),Mn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,isSatisfied:e.Bool.Eq,cardinality:e.Eq.struct({upperBound:e.Num.Eq,lowerBound:e.Num.Eq}),values:e.RA.getUnsortedArrayEq(e.Eq.struct({id:e.Str.Eq,possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Str.Eq)}))}),kn=e.Eq.union().with(t=>t.type===r.Boolean,xn).with(t=>t.type===r.Numeric,vn).with(t=>t.type===r.Component,Nn).with(t=>t.type===r.Choice,Mn),lt={type:e.Str.Eq,id:g,key:m,sourceId:e.Eq.eqNullable(e.Eq.struct({configurationModel:e.Str.Eq,localId:e.Str.Eq})),canContributeToConfigurationSatisfaction:e.Bool.Eq,isSatisfied:e.Bool.Eq},Pn=e.Eq.struct({...lt,selection:e.Str.Eq,possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Bool.Eq),decision:et,nonOptimisticDecision:et}),Bn=e.Eq.struct({...lt,selection:e.Str.Eq,range:e.Eq.struct({max:e.Num.Eq,min:e.Num.Eq}),decimalPlaces:e.Num.Eq,decision:it,nonOptimisticDecision:it}),On=e.Eq.struct({...lt,inclusion:e.Str.Eq,selection:e.Eq.eqNullable(e.Str.Eq),possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Str.Eq),decision:nt,nonOptimisticDecision:nt}),Fn=e.Eq.struct({...lt,cardinality:e.Eq.struct({upperBound:e.Num.Eq,lowerBound:e.Num.Eq}),values:e.RM.getEq(e.Str.Eq,e.Eq.struct({id:e.Str.Eq,possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Str.Eq),decision:ot,nonOptimisticDecision:ot}))}),wt=e.Eq.union().with(t=>t.type===r.Boolean,Pn).with(t=>t.type===r.Numeric,Bn).with(t=>t.type===r.Component,On).with(t=>t.type===r.Choice,Fn),Tn=e.Eq.fromEquals((t,i)=>t.hash===i.hash);e.Eq.struct({isSatisfied:e.Bool.Eq,attributes:e.RM.getEq(m,wt)});e.Eq.struct({isSatisfied:e.Bool.Eq,attributes:e.RM.getEq(m,Tn)});e.Eq.struct({decisionExplanations:e.RA.getUnsortedArrayEq(ue),constraintExplanations:e.RA.getUnsortedArrayEq(le)});e.Eq.struct({type:e.Str.Eq,title:e.Str.Eq,detail:e.Str.Eq,decisionExplanations:e.RA.getUnsortedArrayEq(ue),constraintExplanations:e.RA.getUnsortedArrayEq(le)});const Vn=e.Eq.union().with(t=>t.accessToken!=null,e.Eq.struct({accessToken:e.Str.Eq})).with(t=>t.sessionCreateUrl!=null,e.Eq.struct({sessionCreateUrl:e.Str.Eq})),Wn=e.Eq.struct({rules:e.Eq.eqNullable(e.Eq.union().with(t=>t.type===B.none,e.Eq.struct({type:e.Str.Eq})).with(t=>t.type===B.all,e.Eq.struct({type:e.Str.Eq})).with(t=>t.type===B.specific,e.Eq.struct({type:e.Str.Eq,rules:e.RA.getUnsortedArrayEq(Mt)})))}),jn=e.Eq.struct({attributeId:g,decisions:e.RA.getUnsortedArrayEq(g)}),Un=e.Eq.union().with(t=>t.type===_.Channel,e.Eq.struct({type:e.Str.Eq,channel:e.Str.Eq,deploymentName:e.Str.Eq})).with(t=>t.type===_.Package,e.Eq.struct({type:e.Str.Eq,configurationModelPackage:e.Eq.fromEquals(Le.deepEqual)})),Ln=e.Eq.struct({apiBaseUrl:e.Eq.eqNullable(e.Str.Eq),sessionInitialisationOptions:Vn,configurationModelSource:Un,provideSourceId:e.Eq.eqNullable(e.Bool.Eq),optimisticDecisionOptions:e.Eq.eqNullable(e.Eq.struct({restoreConfiguration:e.Eq.eqNullable(e.Bool.Eq),applySolution:e.Eq.eqNullable(e.Bool.Eq),makeDecision:e.Eq.eqNullable(e.Bool.Eq),makeManyDecisions:e.Eq.eqNullable(e.Bool.Eq)})),allowedInExplain:e.Eq.eqNullable(Wn),usageRuleParameters:e.Eq.eqNullable(e.RR.getEq(e.Str.Eq)),attributeRelations:e.Eq.eqNullable(e.RA.getUnsortedArrayEq(jn))});e.Eq.struct({isSatisfied:e.Bool.Eq,canContributeToSatisfaction:e.RA.getUnsortedArrayEq(m),meta:e.RM.getEq(m,In),decisions:e.RM.getEq(m,Dn),consequences:e.RM.getEq(m,kn)});const _n=e.Eq.struct({isSatisfied:e.Eq.eqNullable(e.Bool.Eq),attributes:e.Eq.struct({added:e.RA.getUnsortedArrayEq(wt),changed:e.RA.getUnsortedArrayEq(wt),removed:e.RA.getUnsortedArrayEq(g)})});let de="error";const Hn=k(t=>{switch(t){case"debug":return["debug","info","warning","error"];case"info":return["info","warning","error"];case"warning":return["warning","error"];case"error":return["error"];case"silent":return[]}}),Z=t=>(...i)=>{if(Hn(de).includes(t))switch(t){case"debug":console.debug(...i);break;case"info":console.info(...i);break;case"warning":console.warn(...i);break;case"error":console.error(...i);break}},z={setLogLevel:t=>{de=t},debug:Z("debug"),info:Z("info"),warn:Z("warning"),error:Z("error")},zn=e.pipe(Qi(),Ji("attributes"));function Pt(t){const i=e.pipe(t.attributes,e.RM.map(n=>Xi(n)?n:ln(n)));return{isSatisfied:t.isSatisfied,attributes:i}}function $n(t){return e.pipe([...t.consequences.values()],e.RA.map(i=>u.match(i).returnType().with({type:r.Boolean},n=>({...n,canContributeToConfigurationSatisfaction:!1,decision:null,nonOptimisticDecision:null})).with({type:r.Numeric},n=>({...n,canContributeToConfigurationSatisfaction:!1,decision:null,nonOptimisticDecision:null})).with({type:r.Component},n=>({...n,canContributeToConfigurationSatisfaction:!1,decision:null,nonOptimisticDecision:null})).with({type:r.Choice},n=>({...n,canContributeToConfigurationSatisfaction:!1,values:e.pipe(n.values,e.RA.map(o=>({...o,decision:null,nonOptimisticDecision:null})),e.RA.map(o=>[o.id,o]),e.RM.fromFoldable(e.Str.Eq,L.first(),e.RA.Foldable))})).exhaustive()),e.RA.map(i=>[i.key,i]),e.RM.fromFoldable(m,L.first(),e.RA.Foldable),i=>({attributes:i,isSatisfied:t.isSatisfied}),pe(t),Pt)}function pe(t){const i=n=>$(Gn(o=>{const s=e.pipe(n,e.RA.elem(m)(o.key));return s!=o.canContributeToConfigurationSatisfaction?e.some({...o,canContributeToConfigurationSatisfaction:s}):x.none}));return n=>e.pipe({...n,isSatisfied:t.isSatisfied??n.isSatisfied},Qn([...(t.meta??e.RM.empty).values(),...(t.decisions??e.RM.empty).values(),...(t.consequences??e.RM.empty).values()]),t.canContributeToSatisfaction?i(t.canContributeToSatisfaction):e.identity)}function $(t){return e.pipe(zn,Ki(e.pipe(t,e.RA.fromSingleOrArray,Nt)))}function he(t,i){return n=>e.pipe(n,e.RM.modifyAt(m)(t,o=>{const s=i(o);return s!=o?me(s):o}),e.O.doIfNone(()=>()=>{z.warn("Didn't found attribute while tying to update it. GlobalAttributeIdKey",t)}),e.O.getOrElse(()=>n))}function Gn(t){return i=>e.pipe(i,e.RM.map(n=>e.pipe(t(n),e.O.filter(o=>o!=n),e.O.map(me),e.O.getOrElse(()=>n))))}function Qn(t){return e.pipe(t,e.RA.fromSingleOrArray,e.RA.map(Kn),$)}function Kn(t){return he(t.key,i=>"type"in t?i.type===r.Choice&&t.type===r.Choice?{...i,...t,values:e.pipe(t.values,e.RA.reduce(i.values,(n,o)=>e.pipe(n,e.RM.modifyAt(e.Str.Eq)(o.id,s=>({...s,...o})),e.O.doIfNone(()=>()=>{z.warn("Didn't found choice value while tying to update it. GlobalAttributeIdKey:",t.key,"Choice Value id:",o.id)}),e.O.getOrElse(()=>n))))}:i.type===r.Boolean&&t.type===r.Boolean?{...i,...t}:i.type===r.Numeric&&t.type===r.Numeric?{...i,...t}:i.type===r.Component&&t.type===r.Component?{...i,...t}:(z.warn("Types of attribute and partial attribute mismatch. AttributeType:",i.type,"PartialAttributeType",t.type),i):{...i,...t})}function me(t){const i={...t};return delete i.hash,i}const fe=e.pipe(e.Str.Eq,e.Eq.contramap(t=>t.id)),Jn={concat:(t,i)=>({...i,values:e.RA.getUnionSemigroup(fe).concat(i.values,t.values)})},Xn={concat:(t,i)=>({...i,values:e.RA.getUnionSemigroup(fe).concat(i.values,t.values)})},ft=L.last(),yt=L.last(),ye={concat:(t,i)=>u.match({x:t,y:i}).with({x:{type:r.Numeric},y:{type:r.Numeric}},({x:n,y:o})=>ft.concat(n,o)).with({x:{type:r.Boolean},y:{type:r.Boolean}},({x:n,y:o})=>ft.concat(n,o)).with({x:{type:r.Component},y:{type:r.Component}},({x:n,y:o})=>ft.concat(n,o)).with({x:{type:r.Choice},y:{type:r.Choice}},({x:n,y:o})=>Jn.concat(n,o)).otherwise(()=>i)},be={concat:(t,i)=>u.match({x:t,y:i}).with({x:{type:r.Numeric},y:{type:r.Numeric}},({x:n,y:o})=>yt.concat(n,o)).with({x:{type:r.Boolean},y:{type:r.Boolean}},({x:n,y:o})=>yt.concat(n,o)).with({x:{type:r.Component},y:{type:r.Component}},({x:n,y:o})=>yt.concat(n,o)).with({x:{type:r.Choice},y:{type:r.Choice}},({x:n,y:o})=>Xn.concat(n,o)).otherwise(()=>i)},Yn=L.last(),Zn=e.RM.getUnionSemigroup(m,L.last()),to=e.RM.getUnionSemigroup(m,ye),eo=e.RM.getUnionSemigroup(m,be);function ge(t){return e.pipe(t,y,T)}function Se(t,i){const n=we(i.consequences),o=Ee(i.affectedDecisions),s={isSatisfied:i.consequences.isConfigurationSatisfied,canContributeToSatisfaction:e.pipe(i.consequences.canAttributeContributeToConfigurationSatisfaction,e.RA.map(ge)),decisions:o,consequences:n};return{configuration:e.pipe(t,pe(s),Pt),rawData:s}}function io(t,i,n){const o=no(n),s=we(i),a=Ee(t),c={isSatisfied:i.isConfigurationSatisfied,canContributeToSatisfaction:e.pipe(i.canAttributeContributeToConfigurationSatisfaction,e.RA.map(ge)),meta:o,decisions:a,consequences:s};return{configuration:$n(c),rawData:c}}function Ee(t){const i=(c,p,d)=>e.pipe(c??[],e.RA.map(h=>({attributeId:y(h.attributeId),decision:h})),e.RA.map(({attributeId:h,decision:w})=>({id:h,key:T(h),...d(p(w),w)}))),n=i(t.booleanDecisions,ne,c=>({type:r.Boolean,decision:c,nonOptimisticDecision:c})),o=i(t.numericDecisions,oe,c=>({type:r.Numeric,decision:c,nonOptimisticDecision:c})),s=i(t.componentDecisions,se,c=>({type:r.Component,decision:c,nonOptimisticDecision:c})),a=i(t.choiceValueDecisions,re,(c,p)=>({type:r.Choice,values:e.RA.of({id:p.choiceValueId,decision:c,nonOptimisticDecision:c})}));return e.pipe([...n,...o,...s,...a],e.RA.map(c=>[c.key,c]),e.RM.fromFoldable(m,ye,e.RA.Foldable))}function we(t){const i=(c,p)=>e.pipe(c??[],e.RA.map(d=>({attributeId:y(d.attributeId),consequence:d})),e.RA.map(({attributeId:d,consequence:h})=>({id:d,key:T(d),...p(h)}))),n=i(t.booleanConsequences,c=>({type:r.Boolean,isSatisfied:c.isSatisfied,possibleDecisionStates:c.possibleDecisionStates,selection:mt(c.selection)})),o=i(t.numericConsequences,c=>({type:r.Numeric,isSatisfied:c.isSatisfied,selection:mt(c.selection),range:{max:c.range.max,min:c.range.min},decimalPlaces:c.decimalPlaces})),s=i(t.componentConsequences,c=>({type:r.Component,isSatisfied:c.isSatisfied,possibleDecisionStates:e.pipe(c.possibleDecisionStates,e.RA.map(ee)),inclusion:Hi(c.inclusion),selection:c.selection?mt(c.selection):null})),a=i(t.choiceConsequences,c=>({type:r.Choice,isSatisfied:c.isSatisfied,cardinality:{lowerBound:c.cardinality.lowerBound,upperBound:c.cardinality.upperBound},values:e.pipe(c.values??[],e.RA.map(p=>({id:p.choiceValueId,possibleDecisionStates:e.pipe(p.possibleDecisionStates,e.RA.map(ie))})))}));return e.pipe([...n,...o,...s,...a],e.RA.map(c=>[c.key,c]),e.RM.fromFoldable(m,be,e.RA.Foldable))}function no(t){return e.pipe((t==null?void 0:t.configurationModels)??[],e.RA.chain(i=>e.pipe(i.globalAttributeIds,e.RA.map(n=>({key:T(y(n)),sourceId:{localId:n.localId,configurationModel:i.configurationModelId}})))),e.RA.map(i=>[i.key,i]),e.RM.fromFoldable(m,Yn,e.RA.Foldable))}function oo(t,i){const{configuration:n,rawData:o}=Se(t,i),s=zi(i.rejectedDecisions);return{configuration:n,rawData:o,result:{rejectedDecisions:s}}}function so(t,i){return n=>{if(n.type!=="PutManyDecisionsConflict")return x.none;const o=e.pipe(n.constraintExplanations??[],e.RA.map(vt)),s=Ae(n.decisionExplanations??[],t,i);return e.some({type:l.MakeManyDecisionsConflict,title:n.title??"",detail:n.detail??"",decisionExplanations:s,constraintExplanations:o})}}function ro(t){const i=Ie(t);return n=>({...i(n.decisionExplanations),...Ce(n.constraintExplanations)})}function Ie(t){const i=u.match(t).returnType().with({question:q.whyIsStateNotPossible,subject:S.boolean},n=>({type:r.Boolean,attributeId:n.attributeId,state:n.state})).with({question:q.whyIsStateNotPossible,subject:S.numeric},n=>({type:r.Numeric,attributeId:n.attributeId,state:n.state})).with({question:q.whyIsStateNotPossible,subject:S.component},n=>({type:r.Component,attributeId:n.attributeId,state:n.state})).with({question:q.whyIsStateNotPossible,subject:S.choiceValue},n=>({type:r.Choice,attributeId:n.attributeId,choiceValueId:n.choiceValueId,state:n.state})).otherwise(()=>null);return n=>({decisionExplanations:Ae(n,i??[],{type:"KeepExistingDecisions"})})}function Ce(t){return{constraintExplanations:e.pipe(t,e.RA.map(vt))}}function Ae(t,i,n){return e.pipe(t,e.RA.map(Li),e.RA.map(o=>{const s=e.pipe(o.causedByBooleanDecisions,e.RA.map(A=>({type:r.Boolean,attributeId:A.attributeId,state:null}))),a=e.pipe(o.causedByNumericDecisions,e.RA.map(A=>({type:r.Numeric,attributeId:A.attributeId,state:null}))),c=e.pipe(o.causedByComponentDecisions,e.RA.map(A=>({type:r.Component,attributeId:A.attributeId,state:null}))),p=e.pipe(o.causedByChoiceValueDecisions,e.RA.map(A=>({type:r.Choice,attributeId:A.attributeId,choiceValueId:A.choiceValueId,state:null}))),d=e.pipe(o.causedByBooleanDecisions,e.RA.concat(o.causedByNumericDecisions),e.RA.concat(o.causedByComponentDecisions),e.RA.concat(o.causedByChoiceValueDecisions)),h=e.pipe(s,e.RA.concat(a),e.RA.concat(c),e.RA.concat(p)),w=e.RA.getUnionSemigroup(ce).concat(h,e.RA.fromSingleOrArray(i));return{causedByDecisions:d,solution:{mode:n,decisions:w}}}))}function qe(t,i){return e.pipe({isSatisfied:i.isSatisfied??t.isSatisfied,canContributeToSatisfaction:i.canContributeToSatisfaction??t.canContributeToSatisfaction,meta:i.meta?Zn.concat(t.meta,i.meta):t.meta,decisions:i.decisions?to.concat(t.decisions,i.decisions):t.decisions,consequences:i.consequences?eo.concat(t.consequences,i.consequences):t.consequences},ao)}function ao(t){const i=e.pipe(t.decisions,e.RM.filterMap(n=>n.type===r.Choice?e.pipe({...n,values:e.pipe(n.values,e.RA.filter(o=>o.decision!=null))},e.O.fromPredicate(o=>e.RA.isNonEmpty(o.values))):n.decision!=null?e.some(n):x.none));return{...t,decisions:i}}function co(t){return[...t.decisions.values()].some(i=>{var n;return i.type===r.Choice?i.values.some(o=>{var s;return((s=o.decision)==null?void 0:s.kind)===E.Explicit}):((n=i.decision)==null?void 0:n.kind)===E.Explicit})}function uo(t){const i=(n,o,s)=>o?[{attributeType:n.type,attributeId:n.id,attributeKey:n.key,kind:o.kind,state:o.state,...s}]:[];return e.pipe(t.decisions,e.RM.values(e.Ord.trivial),e.RA.chain(n=>u.match(n).returnType().with({type:r.Boolean},o=>i(o,o.decision,{})).with({type:r.Numeric},o=>i(o,o.decision,{})).with({type:r.Component},o=>i(o,o.decision,{})).with({type:r.Choice},o=>e.pipe(o.values,e.RA.chain(s=>i(o,s.decision,{choiceValueId:s.id})))).exhaustive()))}function lo(t){return e.pipe(t.decisions,e.RM.values(e.Ord.trivial),e.RA.chain(Re))}function Re(t){return u.match(t).returnType().with({type:r.Boolean},e.flow(po,e.RA.fromOption)).with({type:r.Numeric},e.flow(ho,e.RA.fromOption)).with({type:r.Component},e.flow(mo,e.RA.fromOption)).with({type:r.Choice},fo).exhaustive()}function po(t){var i;return((i=t.decision)==null?void 0:i.kind)===E.Explicit?e.some({type:r.Boolean,attributeId:t.id,state:t.decision.state}):x.none}function ho(t){var i;return((i=t.decision)==null?void 0:i.kind)===E.Explicit?e.some({type:r.Numeric,attributeId:t.id,state:t.decision.state}):x.none}function mo(t){var i;return((i=t.decision)==null?void 0:i.kind)===E.Explicit?e.some({type:r.Component,attributeId:t.id,state:t.decision.state}):x.none}function fo(t){return e.pipe(t.values,e.RA.filter(i=>{var n;return((n=i.decision)==null?void 0:n.kind)===E.Explicit}),e.RA.map(i=>({type:r.Choice,attributeId:t.id,choiceValueId:i.id,state:i.decision.state})))}function yo(t,i){const n=i.decisions.get(T(t.attributeId)),o=n?Re(n):[];return e.pipe(o,e.RA.findFirst(a=>ce.equals(a,t)),e.O.match(()=>t.state==null,a=>kt.equals(a,t)))}function bo(t,i){return e.RA.isEmpty(t)&&i==="KeepExistingDecisions"}const De={Accept:"application/json"};function xe(t){const i=Q(t.apiBaseUrl),n=(o,s)=>v(()=>o(qi(t),{headers:{...De,...s??{}}}));return e.pipe(u.match(t.sessionInitialisationOptions).with({accessToken:u.P.string},o=>n(i.session.sessionPost,{Authorization:`Bearer ${o.accessToken}`})).with({sessionCreateUrl:u.P.string},o=>n(Ci(o.sessionCreateUrl))).exhaustive(),e.TE.map(o=>({sessionContext:t,sessionId:o.sessionId})),e.TE.chain(o=>{const s=v(()=>i.decision.decisionGetAllDecisions({headers:U(o)})),a=v(()=>i.consequence.consequenceGet({headers:U(o)})),c=o.sessionContext.provideSourceId??!1?v(()=>i.meta.metaGet({headers:U(o)})):e.TE.right(null);return e.pipe(He.sequenceS(e.TE.ApplicativePar)({decisions:s,consequences:a,meta:c}),e.TE.map(p=>io(p.decisions,p.consequences,p.meta)),e.TE.map(p=>({...o,configuration:p.configuration,configurationRawData:p.rawData})))}))}function ve(t,i){const n=Ri(t,i);return o=>{if(bo(t,i.type))return e.TE.right({sessionState:o,result:{rejectedDecisions:[]}});const s=Q(o.sessionContext.apiBaseUrl);return e.pipe(v(()=>s.decision.decisionPutMany(n,{headers:U(o)}),so(t,i)),e.TE.map(a=>e.pipe(oo(o.configuration,a),e.I.map(c=>({sessionState:{...o,configurationRawData:qe(o.configurationRawData,c.rawData),configuration:c.configuration},result:c.result})))))}}function go(t){const i=Ai(t);return n=>{if(yo(t,n.configurationRawData))return e.TE.right(n);const o=Q(n.sessionContext.apiBaseUrl);return e.pipe(v(()=>o.decision.decisionPutDecision(i,{headers:U(n)})),e.TE.map(s=>{const{configuration:a,rawData:c}=Se(n.configuration,s);return{...n,configuration:a,configurationRawData:qe(n.configurationRawData,c)}}))}}function So(t,i){const n=(s,a,c,p,d)=>{const h=a(s);return(w,A)=>u.match(i).with("decisions",()=>e.pipe(v(()=>c(w.explain)(h,A)),e.TE.map(Ie(s)))).with("constraints",()=>e.pipe(v(()=>p(w.explain)(h,A)),e.TE.map(Ce))).with("full",()=>e.pipe(v(()=>d(w.explain)(h,A)),e.TE.map(ro(s)))).exhaustive()},o=u.match(t).with({question:q.whyIsNotSatisfied},s=>n(s,Di,a=>a.explainWhyNotSatisfiedDecisions,a=>a.explainWhyNotSatisfiedRules,a=>a.explainWhyNotSatisfied)).with({question:q.whyIsStateNotPossible},s=>n(s,xi,a=>a.explainWhyStateNotPossibleDecisions,a=>a.explainWhyStateNotPossibleRules,a=>a.explainWhyStateNotPossible)).exhaustive();return s=>{const a=Q(s.sessionContext.apiBaseUrl);return o(a,{headers:U(s)})}}function Ne(t){const i=Q(t.sessionContext.apiBaseUrl);return v(()=>i.session.sessionDelete(t.sessionId))}function Eo(t){return i=>Me({...i,sessionContext:t})}function Me(t){return t.sessionId&&Ne({...t,sessionId:t.sessionId})(),e.pipe({...t,sessionId:void 0},e.I.map(i=>e.pipe(ke(i.sessionContext,i.configurationRawData),e.TE.mapLeft(n=>({error:n,sessionState:i})))))}function ke(t,i){return e.pipe(xe(t),e.TE.chain(n=>{const o=lo(i);return e.RA.isNonEmpty(o)?e.pipe(n,ve(o,{type:"DropExistingDecisions",conflictHandling:{type:"Automatic"}}),e.TE.map(s=>s.sessionState)):e.TE.right(n)}))}function v(t,i){return e.pipe(e.TE.tryCatch(t,n=>n),e.TE.match(e.identity,e.identity),e.T.map(n=>{if(n==null||n.data==null&&n.error==null)return e.E.left({type:l.ConnectionError});if(n.data!=null)return e.E.right(n.data);if(n.error!=null){const o=(i==null?void 0:i(n.error))??x.none;if(e.O.isSome(o))return e.E.left(o.value);if(n.error.type!=null&&n.error.title!=null&&n.error.detail!=null)return e.pipe(n.error,vi,e.E.left)}return z.error("Received unknown error format:",n.error),e.E.left({type:l.ServerError})}))}function U(t){return{...De,"X-SESSION-ID":t.sessionId}}function wo(t){return $(Pe(t))}function Io(t,i){const n=()=>$(e.RM.map(o=>u.match(o).returnType().with({type:r.Boolean},s=>({...s,decision:null})).with({type:r.Numeric},s=>({...s,decision:null})).with({type:r.Component},s=>({...s,decision:null})).with({type:r.Choice},s=>({...s,values:e.pipe(s.values,e.RM.map(a=>({...a,decision:null})))})).exhaustive()));return e.pipe([i.type==="DropExistingDecisions"?n():e.identity,e.pipe(t,e.RA.map(Pe),$)],Nt)}function Pe(t){const i=n=>n!=null?{state:n,kind:E.Explicit}:null;return he(T(t.attributeId),n=>u.match({attribute:n,decision:t}).returnType().with({attribute:{type:r.Boolean},decision:{type:r.Boolean}},({attribute:o,decision:s})=>({...o,decision:i(s.state)})).with({attribute:{type:r.Numeric},decision:{type:r.Numeric}},({attribute:o,decision:s})=>({...o,decision:i(s.state)})).with({attribute:{type:r.Component},decision:{type:r.Component}},({attribute:o,decision:s})=>({...o,decision:i(s.state)})).with({attribute:{type:r.Choice},decision:{type:r.Choice}},({attribute:o,decision:s})=>({...o,values:e.pipe(o.values,e.RM.map(a=>({...a,decision:a.id===s.choiceValueId?i(s.state):o.cardinality.upperBound!==1?a.decision:null})))})).otherwise(()=>n))}const Co=e.TE.left({type:l.SessionNotFound});function K(t,i,n){return(...o)=>{const s=t(...o),a=i?i(...o):null;return c=>({type:"StateMutating",itemId:It.guid(),allowSimultaneouslyTermination:n,deferredPromise:Ht(),execute:e.flow(s,e.TE.mapLeft(p=>({...p,type:"ErrorWithSessionState"}))),optimisticAttributeUpdater:c&&a?e.pipe(a,e.RA.fromSingleOrArray,Nt):null})}}function Ao(t){return(...i)=>{const n=t(...i);return{type:"StatePreserving",itemId:It.guid(),deferredPromise:Ht(),execute:e.flow(n,e.TE.mapLeft(o=>({type:"PureError",error:o})))}}}function dt(t){return(...i)=>{const n=t(...i);return(o,s)=>u.match(o).with({sessionId:u.P.not(u.P.nullish)},a=>n(a,s)).otherwise(()=>Co)}}function Bt(t){return(...i)=>{const n=t(...i);return(o,s)=>e.pipe(n(o,s),e.TE.map(a=>({sessionState:a,result:void 0})))}}function Ot(t){return(...i)=>{const n=t(...i);return(o,s)=>e.pipe(n(o,s),e.TE.mapLeft(a=>({error:a,sessionState:null})))}}const qo=e.pipe(go,dt,Bt,Ot,t=>K(t,wo,!0)),tt=e.pipe(ve,dt,Ot,t=>K(t,Io,!0)),Ro=e.pipe(Eo,Bt,t=>K(t,null,!1)),Do=e.pipe(()=>Me,Bt,t=>K(t,null,!1)),xo=e.pipe(So,dt,Ao),vo=t=>{const i=()=>(o,s)=>()=>t&&t.aborted?Promise.reject(t.reason):Promise.resolve(e.E.right({sessionState:o,result:{pendingTasks:s.queuedWork-1}})),n=e.pipe(i,dt,Ot,o=>K(o,null,!1))()(!1);if(t){const o=()=>{n.deferredPromise.reject(t.reason),t.removeEventListener("abort",o)};t.addEventListener("abort",o)}return n},No=t=>{t.forEach(i=>{e.pipe(i.result,e.E.doIfRight(n=>()=>{i.deferredPromise.resolve(n)}),e.E.doIfLeft(n=>()=>{i.deferredPromise.reject(n)}))})},Mo=b.fromPromise(({input:t})=>e.pipe(e.E.tryCatch(t.run,i=>i),e.TE.fromEither,e.TE.chain(i=>e.TE.tryCatch(i,n=>n)),e.T.map(i=>({workItemId:t.workItemId,result:i})))()),ko=t=>t.type==="StatePreserving",Lt=t=>t.type==="StateMutating",_t={type:l.SessionNotFound},Po={type:l.TaskCancelled},Bo=b.setup({types:{input:{},context:{},events:{},emitted:{}},guards:{isSessionNotFoundProblem:({},{result:t})=>e.pipe(t,e.E.match(()=>!1,e.E.match(i=>i.error.type==="SessionNotFound",()=>!1)))},actors:{runTask:Mo,createSessionWithData:b.fromPromise(({input:t})=>ke(t.sessionContext,t.configurationRawData)())},actions:{emitState:b.enqueueActions(({context:t,enqueue:i})=>{const n=Pt(t.work.filter(Lt).reduce((o,s)=>s.optimisticAttributeUpdater?s.optimisticAttributeUpdater(o):o,t.sessionState.configuration));i.assign({deferredPromiseCompletions:e.RA.empty}),i.emit({type:"MachineState",sessionState:{...t.sessionState,configuration:n},deferredPromiseCompletions:t.deferredPromiseCompletions})}),spawnWork:b.enqueueActions(({context:t,enqueue:i})=>{const n=e.pipe(t.work,e.RNEA.fromReadonlyArray,e.O.map(s=>e.pipe(s,e.RNEA.head,e.O.fromPredicate(Lt),e.O.map(e.RA.of),e.O.getOrElse(()=>e.pipe(s,e.RA.takeLeftWhile(ko))))),e.O.getOrElse(()=>e.RA.empty)),o={queuedWork:t.work.length,currentlyRunningWork:n.length};n.forEach(s=>{e.RM.member(e.Str.Eq)(s.itemId,t.runningWork)||i.assign({workExecutionAttemptAmount:({context:a})=>e.pipe(a.workExecutionAttemptAmount,e.RM.addOrUpdate(e.Str.Eq)(s.itemId,()=>1,c=>c+1)),runningWork:({context:a,spawn:c})=>e.pipe(a.runningWork,e.RM.upsertAt(e.Str.Eq)(s.itemId,c("runTask",{input:{workItemId:s.itemId,run:()=>s.execute(a.sessionState,o)}})))})})}),answerAndRemoveWork:b.enqueueActions(({context:t,enqueue:i},n)=>{const o=e.pipe(t.work,e.RA.findFirst(s=>s.itemId===n.workItemId),e.O.toNullable);i.assign({work:({context:s})=>e.pipe(s.work,e.RA.filter(a=>a.itemId!==n.workItemId)),runningWork:({context:s})=>e.pipe(s.runningWork,e.RM.deleteAt(e.Str.Eq)(n.workItemId)),workExecutionAttemptAmount:({context:s})=>e.pipe(s.workExecutionAttemptAmount,e.RM.deleteAt(e.Str.Eq)(n.workItemId))}),o&&i.assign({deferredPromiseCompletions:({context:s})=>e.pipe(s.deferredPromiseCompletions,e.RA.append({deferredPromise:o.deferredPromise,result:n.result}))})}),cancelAllRunningWork:b.enqueueActions(({context:t,enqueue:i})=>{t.runningWork.size>0&&i(b.log(`Cancelling ${t.runningWork.size} running work${t.runningWork.size!==1?"s":""}`)),t.runningWork.forEach(n=>{i.stopChild(n)}),i.assign({runningWork:e.RM.empty})})}}).createMachine({context:({input:t})=>({sessionState:t.sessionState,work:e.RA.empty,runningWork:e.RM.empty,workExecutionAttemptAmount:e.RM.empty,deferredPromiseCompletions:e.RA.empty}),entry:["emitState"],on:{EnqueueWork:{actions:[b.assign({work:({context:t,event:i})=>e.RA.append(i.workItem)(t.work)}),"emitState"]},Shutdown:{target:"#shutdown"}},initial:"processing",states:{processing:{always:{actions:["spawnWork"]},on:{"xstate.done.actor.*":[{target:"restoreSession",guard:{type:"isSessionNotFoundProblem",params:({event:t})=>t.output},actions:[b.log("Work resulted in SessionNotFound"),"cancelAllRunningWork",b.enqueueActions(({enqueue:t,event:i})=>{const{result:n}=i.output;e.pipe(n,e.E.doIfRight(o=>()=>e.pipe(o,e.E.doIfLeft(s=>()=>{s.type==="ErrorWithSessionState"&&s.sessionState&&t.assign({sessionState:s.sessionState})}))))})]},{actions:[b.enqueueActions(({context:t,enqueue:i,event:n})=>{const o=n.output,s=e.pipe(t.work,e.RA.findFirst(c=>c.itemId===o.workItemId),e.O.toNullable),a=t.runningWork.get(o.workItemId);if(s&&a&&n.actorId===a.id)if(e.E.isLeft(o.result))i({type:"answerAndRemoveWork",params:{workItemId:s.itemId,result:e.E.left(o.result.left)}});else{const c=o.result.right;if(s.type==="StateMutating"){const p=c;e.pipe(p,e.E.doIfRight(d=>()=>{i.assign({sessionState:d.sessionState})}),e.E.doIfLeft(d=>()=>{d.sessionState&&i.assign({sessionState:d.sessionState})})),i({type:"answerAndRemoveWork",params:{workItemId:s.itemId,result:e.pipe(p,e.E.map(d=>d.result),e.E.mapLeft(d=>d.error))}})}else{const p=c;i({type:"answerAndRemoveWork",params:{workItemId:s.itemId,result:e.pipe(p,e.E.mapLeft(d=>d.error))}})}}i("emitState")})]}]}},restoreSession:{entry:[b.assign({sessionState:({context:t})=>({...t.sessionState,sessionId:void 0})}),b.enqueueActions(({context:t,enqueue:i})=>{e.pipe(t.workExecutionAttemptAmount,e.RM.filter(o=>o>1),e.RM.keys(e.Ord.trivial)).forEach(o=>{i({type:"answerAndRemoveWork",params:{workItemId:o,result:e.E.left(_t)}})})}),"emitState"],invoke:{src:"createSessionWithData",input:({context:t})=>t.sessionState,onDone:{target:"processing",actions:[b.enqueueActions(({context:t,event:i,enqueue:n})=>{e.pipe(i.output,e.E.doIfRight(o=>()=>{n.assign({sessionState:o})}),e.E.doIfLeft(o=>()=>{n(b.log("Can't restore session because of error: "+JSON.stringify(o))),e.pipe(t.work,e.RA.takeLeftWhile(a=>a.type==="StatePreserving"||a.allowSimultaneouslyTermination)).forEach(a=>{n({type:"answerAndRemoveWork",params:{workItemId:a.itemId,result:e.E.left(_t)}})})}))}),"emitState"]},onError:{target:"processing",actions:[b.log("An unexpected error occurred while trying to restore the session.")]}}},shutdown:{type:"final",id:"shutdown",entry:["cancelAllRunningWork",b.enqueueActions(({context:t,enqueue:i})=>{const n=e.E.left(Po);if(t.work.forEach(o=>{i({type:"answerAndRemoveWork",params:{workItemId:o.itemId,result:n}})}),t.sessionState.sessionId){const o={...t.sessionState,sessionId:t.sessionState.sessionId};i(()=>{Ne(o)().then(()=>{},()=>{})})}}),"emitState"]}}});function Oo(t){return b.createActor(Bo,{input:{sessionState:t}})}const{summon:W}=zt.summonFor({}),pt=W(t=>t.interface({localId:t.string(),componentPath:t.optional(t.array(t.string())),sharedConfigurationModelId:t.optional(t.string())},"GlobalAttributeId")),Fo=W(t=>t.interface({type:t.stringLiteral("Numeric"),attributeId:pt(t),state:t.number()},"NumericDecision")),To=W(t=>t.interface({type:t.stringLiteral("Boolean"),attributeId:pt(t),state:t.boolean()},"NumericDecision")),Vo=W(t=>t.interface({type:t.stringLiteral("Choice"),attributeId:pt(t),choiceValueId:t.string(),state:t.keysOf({Included:null,Excluded:null})},"ChoiceDecision")),Wo=W(t=>t.interface({type:t.stringLiteral("Component"),attributeId:pt(t),state:t.keysOf({Included:null,Excluded:null})},"ComponentDecision")),jo=W(t=>t.taggedUnion("type",{Numeric:Fo(t),Boolean:To(t),Choice:Vo(t),Component:Wo(t)},"Decision")),Uo=W(t=>t.interface({schemaVersion:t.numberLiteral(1),explicitDecisions:t.array(jo(t))},"StoredConfigurationV1")),{summon:Lo}=zt.summonFor({}),_o=Lo(t=>t.taggedUnion("type",{1:Uo(t)},"StoredConfiguration"));function Ho(t){return{schemaVersion:1,explicitDecisions:e.pipe(t,e.RA.map(n=>{const o={localId:n.attributeId.localId,componentPath:n.attributeId.componentPath!=null&&e.RA.isNonEmpty(n.attributeId.componentPath)?n.attributeId.componentPath:void 0,sharedConfigurationModelId:n.attributeId.sharedConfigurationModelId??void 0};return u.match(n).returnType().with({attributeType:r.Numeric},s=>({type:"Numeric",attributeId:o,state:s.state})).with({attributeType:r.Boolean},s=>({type:"Boolean",attributeId:o,state:s.state})).with({attributeType:r.Component},s=>({type:"Component",attributeId:o,state:u.match(s.state).returnType().with(R.Included,()=>"Included").with(R.Excluded,()=>"Excluded").exhaustive()})).with({attributeType:r.Choice},s=>({type:"Choice",attributeId:o,choiceValueId:s.choiceValueId,state:u.match(s.state).returnType().with(I.Included,()=>"Included").with(I.Excluded,()=>"Excluded").exhaustive()})).exhaustive()}))}}function zo(t){return e.E.isLeft(_o.create(t))?e.E.left({type:l.StoredConfigurationInvalid}):e.pipe(t.explicitDecisions,e.RA.map(i=>{const n={localId:i.attributeId.localId,componentPath:i.attributeId.componentPath!=null&&e.RA.isNonEmpty(i.attributeId.componentPath)?i.attributeId.componentPath:void 0,sharedConfigurationModelId:i.attributeId.sharedConfigurationModelId??void 0};return u.match(i).returnType().with({type:"Numeric"},o=>({type:r.Numeric,attributeId:n,state:o.state})).with({type:"Boolean"},o=>({type:r.Boolean,attributeId:n,state:o.state})).with({type:"Component"},o=>({type:r.Component,attributeId:n,state:u.match(o.state).with("Included",()=>R.Included).with("Excluded",()=>R.Excluded).exhaustive()})).with({type:"Choice"},o=>({type:r.Choice,attributeId:n,choiceValueId:o.choiceValueId,state:u.match(o.state).with("Included",()=>I.Included).with("Excluded",()=>I.Excluded).exhaustive()})).exhaustive()}),e.E.right)}class Be{constructor(i){this.previousValue=null,this.currentValue=null,this.calculateChangeSetFn=k(i)}setValue(i){this.currentValue=i}clearChanges(){this.previousValue=this.currentValue}getChanges(){return this.calculateChangeSetFn(this.previousValue,this.currentValue)}}class j{constructor(i){this.listeners=new Map,this.currentValue=null,this.calculateChangeSetFn=k(i),this.changesHandler=new Be(i)}addListener(i){const n=It.guid();this.listeners.set(n,i);const o=this.calculateChangeSetFn(null,this.currentValue);return e.O.isSome(o)&&i(...o.value),{unsubscribe:()=>{this.listeners.delete(n)}}}notifyListeners(i){if(this.currentValue=i,this.changesHandler.setValue(i),this.listeners.size>0){const n=this.changesHandler.getChanges();e.O.isSome(n)&&this.listeners.forEach(o=>o(...n.value))}this.changesHandler.clearChanges()}unsubscribeAllListeners(){this.listeners.clear()}}const Oe={isSatisfied:null,attributes:{added:[],changed:[],removed:[]}};function $o(t){return _n.equals(Oe,t)}function Go(t){return(i,n)=>{const o=i?t(i):null,s=n?t(n):null;return s!=null&&s!==o?e.some([s]):x.none}}function Qo(t,i){const n=e.RM.keys(e.Ord.trivial);if(i==null)return x.none;const o=(t==null?void 0:t.attributes)??e.RM.empty,s=e.pipe([...n(i.attributes),...n(o)],e.RA.uniq(m)),a=[],c=[],p=[];return s.forEach(d=>{const h=i.attributes.get(d),w=o.get(d);h!=null&&w==null&&a.push(h),h==null&&w!=null&&p.push(w.id),h!=null&&w!=null&&h.hash!=w.hash&&c.push(h)}),e.pipe({isSatisfied:i.isSatisfied!=(t==null?void 0:t.isSatisfied)?i.isSatisfied:null,attributes:{added:a,changed:c,removed:p}},e.O.fromPredicate(e.P.not($o)),e.O.map(d=>[i,d]))}function Ko(t){return Fe(t)}function bt(t){return Fe(t)}function Fe(t){return(i,n)=>{if(n==null||i===n)return x.none;const o=t(n);return e.some([o])}}class Jo{constructor(i){this.canResetConfigurationMemo=k(co,{maxSize:5}),this.calculateConfigurationChangedHandlerMemo=k(Qo,{maxSize:5}),this.getCollectedDecisionsMemo=k(uo),this.getCollectedImplicitDecisionsMemo=k(e.flow(this.getCollectedDecisionsMemo.bind(this),e.RA.filter(Kt))),this.getCollectedExplicitDecisionsMemo=k(e.flow(this.getCollectedDecisionsMemo.bind(this),e.RA.filter(Qt))),this.getStoredConfigurationMemo=k(e.flow(this.getCollectedExplicitDecisionsMemo.bind(this),Ho)),this.sessionChangesHandler=new Be(this.calculateConfigurationChangedHandlerMemo.bind(this)),this.configurationChangedSubscriptionHandler=new j(this.calculateConfigurationChangedHandlerMemo.bind(this)),this.canResetConfigurationSubscriptionHandler=new j(Go(this.canResetConfigurationMemo.bind(this))),this.storedConfigurationSubscriptionHandler=new j(Ko(this.getStoredConfigurationMemo.bind(this))),this.decisionsSubscriptionHandler=new j(bt(this.getCollectedDecisionsMemo.bind(this))),this.explicitDecisionsSubscriptionHandler=new j(bt(this.getCollectedExplicitDecisionsMemo.bind(this))),this.implicitDecisionsSubscriptionHandler=new j(bt(this.getCollectedImplicitDecisionsMemo.bind(this))),this.hashedConfigurationInputHandler=[this.sessionChangesHandler.setValue.bind(this.sessionChangesHandler),this.configurationChangedSubscriptionHandler.notifyListeners.bind(this.configurationChangedSubscriptionHandler)],this.rawDataInputHandlers=[this.canResetConfigurationSubscriptionHandler,this.storedConfigurationSubscriptionHandler,this.decisionsSubscriptionHandler,this.explicitDecisionsSubscriptionHandler,this.implicitDecisionsSubscriptionHandler],this.sessionState=null,this.handleActorUpdate({sessionState:i,deferredPromiseCompletions:e.RA.empty}),this.actor=Oo(i),this.subscription=this.actor.on("MachineState",n=>{this.handleActorUpdate(n)}),this.actor.start()}getDecisions(i,n){const o=c=>(this.throwIfSessionClosed(),u.match(c).with(E.Explicit,()=>this.getCollectedExplicitDecisionsMemo.bind(this)).with(E.Implicit,()=>this.getCollectedImplicitDecisionsMemo.bind(this)).with(u.P.nullish,()=>this.getCollectedDecisionsMemo.bind(this)).exhaustive()(this.sessionState.configurationRawData)),s=typeof i=="string"?i:void 0,a=typeof i=="boolean"?i:n;return this.executeMaybeQueued(a===!0,()=>o(s))}async storeConfiguration(){return this.executeMaybeQueued(!0,()=>(this.throwIfSessionClosed(),this.getStoredConfigurationMemo(this.sessionState.configurationRawData)))}async restoreConfiguration(i,n){var a;this.throwIfSessionClosed();const o=zo(i);if(e.E.isLeft(o))throw o.left;const s=e.pipe(tt(o.right,n),e.I.ap(((a=this.sessionState.sessionContext.optimisticDecisionOptions)==null?void 0:a.restoreConfiguration)??!1));return this.actor.send({type:"EnqueueWork",workItem:s}),await s.deferredPromise.promise}canResetConfiguration(i){return this.executeMaybeQueued(i===!0,()=>(this.throwIfSessionClosed(),this.canResetConfigurationMemo(this.sessionState.configurationRawData)))}async resetConfiguration(){var n;this.throwIfSessionClosed();const i=e.pipe(tt([],{type:"DropExistingDecisions",conflictHandling:{type:"Automatic"}}),e.I.ap(((n=this.sessionState.sessionContext.optimisticDecisionOptions)==null?void 0:n.resetConfiguration)??!1));this.actor.send({type:"EnqueueWork",workItem:i}),await i.deferredPromise.promise}addConfigurationChangedListener(i){return this.throwIfSessionClosed(),this.configurationChangedSubscriptionHandler.addListener(i)}addCanResetConfigurationChangedListener(i){return this.throwIfSessionClosed(),this.canResetConfigurationSubscriptionHandler.addListener(i)}addStoredConfigurationChangedListener(i){return this.throwIfSessionClosed(),this.storedConfigurationSubscriptionHandler.addListener(i)}addDecisionsChangedListener(i,n){this.throwIfSessionClosed();const o=typeof i=="string"?i:void 0,s=typeof i!="string"?i:n;if(s==null)throw new Error("The handler is null or undefined");return o===E.Explicit?this.explicitDecisionsSubscriptionHandler.addListener(s):o===E.Implicit?this.implicitDecisionsSubscriptionHandler.addListener(s):this.decisionsSubscriptionHandler.addListener(s)}getSessionContext(i){return this.executeMaybeQueued(i===!0,()=>(this.throwIfSessionClosed(),this.sessionState.sessionContext))}getConfiguration(i){return this.executeMaybeQueued(i===!0,()=>(this.throwIfSessionClosed(),this.sessionState.configuration))}getConfigurationChanges(){return this.throwIfSessionClosed(),e.pipe(this.sessionChangesHandler.getChanges(),e.O.map(Ge.snd),e.O.getOrElse(()=>Oe))}clearConfigurationChanges(){this.throwIfSessionClosed(),this.sessionChangesHandler.clearChanges()}async makeDecision(i){var o;this.throwIfSessionClosed();const n=e.pipe(i,qo,e.I.ap(((o=this.sessionState.sessionContext.optimisticDecisionOptions)==null?void 0:o.makeDecision)??!0));this.actor.send({type:"EnqueueWork",workItem:n}),await n.deferredPromise.promise}async applySolution(i){var o;this.throwIfSessionClosed();const n=e.pipe(tt(i.decisions,i.mode),e.I.ap(((o=this.sessionState.sessionContext.optimisticDecisionOptions)==null?void 0:o.applySolution)??!0));return this.actor.send({type:"EnqueueWork",workItem:n}),await n.deferredPromise.promise}setMany(i,n){return this.makeManyDecisions(i,n)}async makeManyDecisions(i,n){var s;this.throwIfSessionClosed();const o=e.pipe(tt(i,n),e.I.ap(((s=this.sessionState.sessionContext.optimisticDecisionOptions)==null?void 0:s.makeManyDecisions)??!0));return this.actor.send({type:"EnqueueWork",workItem:o}),await o.deferredPromise.promise}async setSessionContext(i){this.throwIfSessionClosed();const n=e.pipe(i,Ro,e.I.ap(!1));this.actor.send({type:"EnqueueWork",workItem:n}),await n.deferredPromise.promise}async reinitialize(){this.throwIfSessionClosed();const i=e.pipe(Do(),e.I.ap(!1));this.actor.send({type:"EnqueueWork",workItem:i}),await i.deferredPromise.promise}async explain(i,n){this.throwIfSessionClosed();const o=typeof i=="function"?i(xt):i,s=xo(o,n);return this.actor.send({type:"EnqueueWork",workItem:s}),await s.deferredPromise.promise}async close(){this.actor.getSnapshot().status==="active"&&(this.subscription.unsubscribe(),this.actor.send({type:"Shutdown"}),await b.waitFor(this.actor,i=>i.status!=="active"),this.configurationChangedSubscriptionHandler.unsubscribeAllListeners())}async scheduleTask(i){this.throwIfSessionClosed();const n=vo(i);return this.actor.send({type:"EnqueueWork",workItem:n}),await n.deferredPromise.promise}executeMaybeQueued(i,n,o){return this.throwIfSessionClosed(),i?this.scheduleTask(o).then(()=>n()):n()}handleActorUpdate(i){this.sessionState=i.sessionState,this.hashedConfigurationInputHandler.forEach(n=>n(this.sessionState.configuration)),this.rawDataInputHandlers.forEach(n=>n.notifyListeners(this.sessionState.configurationRawData)),No(i.deferredPromiseCompletions)}throwIfSessionClosed(){if(this.actor.getSnapshot().status!=="active")throw{type:l.SessionClosed}}}const Xo={async createSession(t){return e.pipe(xe(t),e.TE.map(i=>new Jo(i)),e.T.chain(e.E.match(i=>()=>Promise.reject(i),i=>()=>Promise.resolve(i))))()}};exports.AllowedRulesInExplainType=B;exports.AttributeInterpreter=mi;exports.AttributeRefinements=Ke;exports.AttributeType=r;exports.ChoiceValueDecisionState=I;exports.ChoiceValueInterpreter=ci;exports.CollectedDecisionRefinements=Ei;exports.ComponentDecisionState=R;exports.ConfigurationInterpreter=ai;exports.ConfigurationModelSourceType=_;exports.ConfiguratorErrorType=l;exports.DecisionKind=E;exports.ExplainQuestionBuilderModule=fi;exports.ExplainQuestionSubject=S;exports.ExplainQuestionType=q;exports.GlobalAttributeIdKeyBuilder=T;exports.Inclusion=H;exports.Logger=z;exports.Selection=V;exports.SessionFactory=Xo;exports.StoredConfigurationV1=Qe;exports.explainQuestionBuilder=xt;exports.globalAttributeIdEq=g;exports.globalAttributeIdKeyEq=m;exports.globalConstraintIdEq=Mt;exports.sessionContextEq=Ln;