UNPKG

@viamedici-spc/configurator-ts

Version:

TypeScript library to build configurator web applications based on the Viamedici Headless Configuration Engine (HCE).

8 lines 71.8 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@viamedici-spc/fp-ts-extensions"),l=require("ts-pattern"),b=require("xstate"),We=require("spark-md5"),je=require("fast-equals"),P=require("memize"),It=require("dyna-guid"),Ht=require("@morphic-ts/batteries/lib/summoner-ESBAST");var p=(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.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.SessionParametersInvalid="SessionParametersInvalid",t))(p||{}),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||{}),L=(t=>(t.Channel="Channel",t.Package="Package",t))(L||{}),a=(t=>(t.Boolean="Boolean",t.Numeric="Numeric",t.Choice="Choice",t.Component="Component",t))(a||{}),w=(t=>(t.Included="Included",t.Excluded="Excluded",t))(w||{}),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||{}),_=(t=>(t.Always="Always",t.Optional="Optional",t))(_||{});const Ue=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),wt=t=>t.type===a.Boolean,Ct=t=>t.type===a.Choice,At=t=>t.type===a.Numeric,qt=t=>t.type===a.Component,Le=Object.freeze(Object.defineProperty({__proto__:null,booleanAttributeRefinement:wt,choiceAttributeRefinement:Ct,componentAttributeRefinement:qt,numericAttributeRefinement:At},Symbol.toStringTag,{value:"Module"}));function Rt(t){return t}function _e(t){return function(){return t}}function He(t,i,n,o,s,r,c,u,d){switch(arguments.length){case 1:return t;case 2:return function(){return i(t.apply(this,arguments))};case 3:return function(){return n(i(t.apply(this,arguments)))};case 4:return function(){return o(n(i(t.apply(this,arguments))))};case 5:return function(){return s(o(n(i(t.apply(this,arguments)))))};case 6:return function(){return r(s(o(n(i(t.apply(this,arguments))))))};case 7:return function(){return c(r(s(o(n(i(t.apply(this,arguments)))))))};case 8:return function(){return u(c(r(s(o(n(i(t.apply(this,arguments))))))))};case 9:return function(){return d(u(c(r(s(o(n(i(t.apply(this,arguments)))))))))}}}var ze={_tag:"None"},$e=Object.prototype.hasOwnProperty,Ge=function(){return function(t){return!0}};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 Qe(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],r=e.pipe(o.id.componentPath??[],n?e.RA.takeLeft(s.length):e.identity);return e.RA.getEq(e.Str.Eq).equals(s,r)}))}function Ke(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 Je(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 ot(t){return i=>e.pipe(i.attributes,e.RM.filter(t),e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([n,o])=>o))}function Xe(t){return ot(Ct)(t)}function Ye(t){return ot(qt)(t)}function Ze(t){return ot(At)(t)}function ti(t){return ot(wt)(t)}function $(t,i,n){const o=typeof i=="string"?i:T(i),s=t.attributes.get(o);return s&&(n??Ge)(s)?s:void 0}function zt(t,i){return $(t,i,Ct)}function ei(t,i,n){const o=zt(t,i);return((o==null?void 0:o.values)??e.RM.empty).get(n)}function ii(t,i){return $(t,i,At)}function ni(t,i){return $(t,i,wt)}function oi(t,i){return $(t,i,qt)}const si=Object.freeze(Object.defineProperty({__proto__:null,getAttribute:$,getAttributesOfComponentAttribute:Qe,getAttributesOfRootConfigurationModel:Je,getAttributesOfSharedConfigurationModel:Ke,getBooleanAttribute:ni,getBooleanAttributes:ti,getChoiceAttribute:zt,getChoiceAttributes:Xe,getChoiceValue:ei,getComponentAttribute:oi,getComponentAttributes:Ye,getNumericAttribute:ii,getNumericAttributes:Ze},Symbol.toStringTag,{value:"Module"}));function Dt(t){return t.possibleDecisionStates.includes(w.Included)}function $t(t){return!Dt(t)}const ri=Object.freeze(Object.defineProperty({__proto__:null,isAllowed:Dt,isBlocked:$t},Symbol.toStringTag,{value:"Module"}));function ai(t){return l.match(t).with({type:a.Choice},i=>i.cardinality.lowerBound>0).with({type:a.Boolean},i=>i.selection===V.Mandatory).with({type:a.Numeric},i=>i.selection===V.Mandatory).with({type:a.Component},i=>i.inclusion===_.Optional&&i.selection===V.Mandatory).exhaustive()}function ci(t){return t.cardinality.upperBound>1}function ui(t){return e.pipe(t.values,e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([i,n])=>n),e.RA.filter(Dt))}function li(t){return e.pipe(t.values,e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([i,n])=>n),e.RA.filter($t))}function di(t){return e.pipe(t.values,e.RM.filter(i=>{var n;return((n=i.decision)==null?void 0:n.state)===w.Included}),e.RM.toReadonlyArray(e.Ord.trivial),e.RA.map(([i,n])=>n))}const pi=Object.freeze(Object.defineProperty({__proto__:null,getAllowedChoiceValues:ui,getBlockedChoiceValues:li,getIncludedChoiceValues:di,isChoiceAttributeMultiSelect:ci,isMandatory:ai},Symbol.toStringTag,{value:"Module"})),vt={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})})}},hi=Object.freeze(Object.defineProperty({__proto__:null,explainQuestionBuilder:vt},Symbol.toStringTag,{value:"Module"})),mi=t=>t.attributeType===a.Boolean,fi=t=>t.attributeType===a.Numeric,yi=t=>t.attributeType===a.Component,bi=t=>t.attributeType===a.Choice,Gt=t=>t.kind===E.Explicit,Qt=t=>t.kind===E.Implicit,gi=Object.freeze(Object.defineProperty({__proto__:null,collectedBooleanDecisionRefinement:mi,collectedChoiceDecisionRefinement:bi,collectedComponentDecisionRefinement:yi,collectedExplicitDecisionRefinement:Gt,collectedImplicitDecisionRefinement:Qt,collectedNumericDecisionRefinement:fi},Symbol.toStringTag,{value:"Module"}));var k=(t=>(t.Included="Included",t.Excluded="Excluded",t))(k||{}),bt=(t=>(t.Mandatory="Mandatory",t.Optional="Optional",t))(bt||{}),gt=(t=>(t.Always="Always",t.Optional="Optional",t))(gt||{}),St=(t=>(t.Implicit="Implicit",t.Explicit="Explicit",t))(St||{}),C=(t=>(t.Included="Included",t.Excluded="Excluded",t.Undefined="Undefined",t))(C||{});class Si{constructor(i={}){this.baseUrl="https://integration-tests-ts.spc.viamedici.dev/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 r=n[s];return o.append(s,r instanceof Blob?r:typeof r=="object"&&r!==null?JSON.stringify(r):`${r}`),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:r,query:c,format:u,baseUrl:d,cancelToken:h,...I})=>{const A=(typeof o=="boolean"?o:this.baseApiParams.secure)&&this.securityWorker&&await this.securityWorker(this.securityData)||{},K=this.mergeRequestParams(I,A),Ft=c&&this.toQueryString(c),Ve=this.contentFormatters[r||"application/json"],Tt=u||K.format;return this.customFetch(`${d||this.baseUrl||""}${s}${Ft?`?${Ft}`:""}`,{...K,headers:{...K.headers||{},...r&&r!=="multipart/form-data"?{"Content-Type":r}:{}},signal:(h?this.createAbortSignal(h):K.signal)||null,body:typeof n>"u"||n===null?null:Ve(n)}).then(async pt=>{const M=pt;M.data=null,M.error=null;const Vt=Tt?await pt[Tt]().then(J=>(M.ok?M.data=J:M.error=J,M)).catch(J=>(M.error=J,M)):M;if(h&&this.abortControllers.delete(h),!pt.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 Configuration Engine * @version 2026.3.6-integration-tests-ts.1 * @license © 2026 Viamedici - All rights reserved (https://viamedici.de) * @termsOfService None * @baseUrl https://integration-tests-ts.spc.viamedici.dev/hca/api/engine * @contact Viamedici Software GmbH <info@viamedici.de> (https://viamedici.de) */class Kt extends Si{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.obsoletion={obsoletionGetObsoletion:(i={})=>this.request({path:"/v2/obsoletion",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 Ei="https://spc.viamedici.io/hca/api/engine",Wt=new Map,jt=new Map;function G(t){const i=t??Ei;let n=Wt.get(i);return n||(n=new Kt({baseUrl:i}),Wt.set(i,n)),n}function Ii(t){const i=(...o)=>typeof o[0]=="string"?fetch(t,o[1]):fetch(...o);let n=jt.get(t);return n||(n=new Kt({customFetch:i}),jt.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 Jt(t){return{type:"Choice",attributeId:D(t.attributeId),choiceValueId:t.choiceValueId,state:l.match(t.state).with(l.P.nullish,()=>C.Undefined).with(w.Included,()=>C.Included).with(w.Excluded,()=>C.Excluded).exhaustive()}}function Xt(t){return{type:"Component",attributeId:D(t.attributeId),state:l.match(t.state).with(l.P.nullish,()=>C.Undefined).with(R.Included,()=>C.Included).with(R.Excluded,()=>C.Excluded).exhaustive()}}function Yt(t){return{type:"Numeric",attributeId:D(t.attributeId),state:t.state}}function Zt(t){return{type:"Boolean",attributeId:D(t.attributeId),state:t.state}}function wi(t){return l.match(t).with({type:a.Choice},Jt).with({type:a.Component},Xt).with({type:a.Boolean},Zt).with({type:a.Numeric},Yt).exhaustive()}function Ci(t){const i=l.match(t.configurationModelSource).returnType().with({type:L.Channel},r=>({type:"Channel",deploymentName:r.deploymentName,channel:r.channel})).with({type:L.Package},r=>({type:"Package",configurationModelPackage:r.configurationModelPackage})).exhaustive(),n=()=>{var c;const r=(c=t.allowedInExplain)!=null&&c.rules?l.match(t.allowedInExplain.rules).returnType().with({type:B.all},()=>({type:"AllowedRulesAll"})).with({type:B.none},()=>({type:"AllowedRulesNone"})).with({type:B.specific},u=>({type:"AllowedRulesSpecific",rules:e.pipe(u.rules,e.RA.map(d=>({configurationModelId:d.configurationModelId,localId:d.localId})),e.RA.toArray)})).exhaustive():void 0;if(r)return{rules:r}},o=t.attributeRelations?e.pipe(t.attributeRelations,e.RA.map(r=>({attributeId:D(r.attributeId),decisions:e.pipe(r.decisions,e.RA.map(D),e.RA.toArray)})),e.RA.toArray):void 0,s=t.wizardAttributeRelations?e.pipe(t.wizardAttributeRelations,e.RA.map(r=>({attributes:e.pipe(r.attributes,e.RA.map(D),e.RA.toArray)})),e.RA.toArray):void 0;return{configurationModelSource:i,allowedInExplain:n(),attributeRelations:o,wizardAttributeRelations:s,disableConfigurationModelTrimming:t.disableConfigurationModelTrimming}}function Ai(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===a.Boolean,Zt),s=n(d=>d.type===a.Numeric,Yt),r=n(d=>d.type===a.Component,Xt),c=n(d=>d.type===a.Choice,Jt),u=l.match(i).with({type:"DropExistingDecisions"},d=>({type:"DropExistingDecisions",conflictResolution:l.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:r,numericDecisions:s,choiceDecisions:c,mode:u}}function qi(t){return l.match(t).returnType().with({subject:S.configuration},()=>({type:"Configuration"})).with({subject:S.attribute},i=>({type:"Attribute",attributeId:D(i.attributeId)})).exhaustive()}function Ri(t){return l.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:l.match(i.state).with(R.Included,()=>k.Included).with(R.Excluded,()=>k.Excluded).exhaustive()})).with({subject:S.choiceValue},i=>({type:"ChoiceValue",attributeId:D(i.attributeId),choiceValueId:i.choiceValueId,state:l.match(i.state).with(w.Included,()=>k.Included).with(w.Excluded,()=>k.Excluded).exhaustive()})).exhaustive()}const X={type:p.ServerError};function Di(t){return l.match(t).returnType().with({type:"ConfigurationModelNotFeasible"},vi).with({type:"SpecifiedDeploymentForbidden"},xi).with({type:"AttributeNotFound"},Ni).with({type:"ChoiceAttributeNotFound"},Mi).with({type:"ComponentAttributeNotFound"},Pi).with({type:"NumericAttributeNotFound"},ki).with({type:"BooleanAttributeNotFound"},Bi).with({type:"ChoiceValueNotFound"},Oi).with({type:"NumericDecisionOutOfRange"},Fi).with({type:"ConflictWithConsequence"},Ti).with({type:"DecisionsToRespectInvalid"},Vi).with({type:"SessionNotFound"},Wi).with({type:"PutManyDecisionsConflict"},()=>X).with({type:"AssignedChannelNotFound"},()=>X).with({type:"InternalServerError"},()=>X).with({type:"RequestTimeout"},i=>f(i,p.RequestTimeout)).with({type:"RequestFailure"},i=>f(i,p.RequestFailure)).with({type:"SerializationError"},i=>f(i,p.SerializationError)).with({type:"MissingTenantIdClaim"},i=>f(i,p.MissingTenantIdClaim)).with({type:"MissingSessionIdClaim"},i=>f(i,p.MissingSessionIdClaim)).with({type:"TenantAccessForbidden"},i=>f(i,p.TenantAccessForbidden)).with({type:"SessionIdInvalid"},i=>f(i,p.SessionIdInvalid)).with({type:"AuthenticationFailure"},i=>f(i,p.AuthenticationFailure)).with({type:"SideLoadingForbidden"},i=>f(i,p.SideLoadingForbidden)).with({type:"ConfigurationModelInvalid"},i=>f(i,p.ConfigurationModelInvalid)).with({type:"SolutionNotFeasible"},i=>f(i,p.SolutionNotFeasible)).with({type:"ConfigurationModelNotFound"},i=>f(i,p.ConfigurationModelNotFound)).with({type:"SolverInitializationFailure"},i=>f(i,p.SolverInitializationFailure)).with({type:"ConfigurationModelLoadFailure"},i=>f(i,p.ConfigurationModelLoadFailure)).with({type:"ConfigurationInitializationFailure"},i=>f(i,p.ConfigurationInitializationFailure)).with({type:"SolverPoolInitializationFailure"},i=>f(i,p.SolverPoolInitializationFailure)).with({type:"SetDecisionConflict"},i=>f(i,p.SetDecisionConflict)).with({type:"SolveOperationTimeout"},i=>f(i,p.SolveOperationTimeout)).with({type:"ExplainConflict"},i=>f(i,p.ExplainConflict)).with({type:"ExplainFailure"},i=>f(i,p.ExplainFailure)).with({type:"SnapshotInvalid"},i=>f(i,p.SnapshotInvalid)).with({type:"SnapshotNotFound"},i=>f(i,p.SnapshotNotFound)).with({type:"SessionParametersInvalid"},i=>f(i,p.SessionParametersInvalid)).otherwise(()=>X)}function f(t,i){return{...t,type:i}}function vi(t){return{...t,type:p.ConfigurationModelNotFeasible,constraintExplanations:e.pipe(t.constraintExplanations??[],e.RA.map(xt))}}function xi(t){return{...t,type:p.SpecifiedDeploymentForbidden}}function Ni(t){return{...t,type:p.AttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Mi(t){return{...t,type:p.ChoiceAttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Pi(t){return{...t,type:p.ComponentAttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function ki(t){return{...t,type:p.NumericAttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Bi(t){return{...t,type:p.BooleanAttributeNotFound,globalAttributeId:y(t.globalAttributeId)}}function Oi(t){const{globalChoiceValueId:i,...n}=t;return{...n,type:p.ChoiceValueNotFound,globalAttributeId:y(i.attributeId),choiceValueId:i.choiceValueId}}function Fi(t){return{...t,type:p.NumericDecisionOutOfRange,globalAttributeId:y(t.globalAttributeId)}}function Ti(t){return{...t,type:p.ConflictWithConsequence,globalAttributeId:y(t.globalAttributeId)}}function Vi(t){return{...t,type:p.DecisionsToRespectInvalid,globalAttributeId:y(t.globalAttributeId)}}function Wi(){return{type:p.SessionNotFound}}function ji(t){const i=e.pipe(t.causedByBooleanDecisions,e.RA.map(r=>({type:a.Boolean,attributeId:y(r.attributeId),state:r.state}))),n=e.pipe(t.causedByNumericDecisions,e.RA.map(r=>({type:a.Numeric,attributeId:y(r.attributeId),state:r.state}))),o=e.pipe(t.causedByComponentDecisions,e.RA.map(r=>({type:a.Component,attributeId:y(r.attributeId),state:te(r.state)}))),s=e.pipe(t.causedByChoiceDecisions,e.RA.map(r=>({type:a.Choice,attributeId:y(r.attributeId),choiceValueId:r.choiceValueId,state:ee(r.state)})));return{causedByBooleanDecisions:i,causedByNumericDecisions:n,causedByComponentDecisions:o,causedByChoiceValueDecisions:s}}function xt(t){const i=e.pipe(t.causedByCardinalities,e.RA.map(o=>y(o.attributeId))),n=e.pipe(t.causedByRules,e.RA.map(o=>Ui(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 Ui(t){return{localId:t.localId,configurationModelId:t.configurationModelId}}function te(t){return l.match(t).with(k.Included,()=>R.Included).with(k.Excluded,()=>R.Excluded).exhaustive()}function ee(t){return l.match(t).with(k.Included,()=>w.Included).with(k.Excluded,()=>w.Excluded).exhaustive()}function st(t){return l.match(t).with(St.Explicit,()=>E.Explicit).with(St.Implicit,()=>E.Implicit).exhaustive()}function ie({state:t,kind:i}){return t!=null?{state:t,kind:st(i)}:null}function ne({state:t,kind:i}){return t!=null?{state:t,kind:st(i)}:null}function oe({state:t,kind:i}){return t===C.Included||t===C.Excluded?{state:l.match(t).with(C.Included,()=>R.Included).with(C.Excluded,()=>R.Excluded).exhaustive(),kind:st(i)}:null}function se({state:t,kind:i}){return t===C.Included||t===C.Excluded?{state:l.match(t).with(C.Included,()=>w.Included).with(C.Excluded,()=>w.Excluded).exhaustive(),kind:st(i)}:null}function ht(t){return l.match(t).with(bt.Mandatory,()=>V.Mandatory).with(bt.Optional,()=>V.Optional).exhaustive()}function Li(t){return l.match(t).with(gt.Always,()=>_.Always).with(gt.Optional,()=>_.Optional).exhaustive()}function _i(t){const i=e.pipe(t.componentDecisions,e.RA.map(r=>{var c;return{type:a.Component,attributeId:y(r.attributeId),state:(c=oe(r))==null?void 0:c.state}})),n=e.pipe(t.booleanDecisions,e.RA.map(r=>{var c;return{type:a.Boolean,attributeId:y(r.attributeId),state:(c=ie(r))==null?void 0:c.state}})),o=e.pipe(t.numericDecisions,e.RA.map(r=>{var c;return{type:a.Numeric,attributeId:y(r.attributeId),state:(c=ne(r))==null?void 0:c.state}})),s=e.pipe(t.choiceValueDecisions,e.RA.map(r=>{var c;return{type:a.Choice,attributeId:y(r.attributeId),choiceValueId:r.choiceValueId,state:(c=se(r))==null?void 0:c.state}}));return e.pipe(s,e.RA.concat(i),e.RA.concat(o),e.RA.concat(n))}function re(t,i,n){return function(o){for(var s=Array(n.length+1),r=0;r<n.length;r++)s[r]=n[r];return s[n.length]=o,i===0?t.apply(null,s):re(t,i-1,s)}}function Hi(t){var i=t.length;switch(i){case 1:return function(n){var o;return o={},o[t[0]]=n,o};case 2:return function(n){return function(o){var s;return s={},s[t[0]]=n,s[t[1]]=o,s}};case 3:return function(n){return function(o){return function(s){var r;return r={},r[t[0]]=n,r[t[1]]=o,r[t[2]]=s,r}}};case 4:return function(n){return function(o){return function(s){return function(r){var c;return c={},c[t[0]]=n,c[t[1]]=o,c[t[2]]=s,c[t[3]]=r,c}}}};case 5:return function(n){return function(o){return function(s){return function(r){return function(c){var u;return u={},u[t[0]]=n,u[t[1]]=o,u[t[2]]=s,u[t[3]]=r,u[t[4]]=c,u}}}}};default:return re(function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];for(var s={},r=0;r<i;r++)s[t[r]]=n[r];return s},i-1,[])}}function zi(t){return function(i){for(var n=Object.keys(i),o=n.length,s=Hi(n),r=t.map(i[n[0]],s),c=1;c<o;c++)r=t.ap(r,i[n[c]]);return r}}var Ut=function(){return{concat:Rt}},rt=function(){return{concat:function(t,i){return i}}},v=ze,ae=function(t,i){return{get:t,set:i}},$i=function(){return ae(Rt,_e)},Gi=function(t){return function(i){return ae(function(n){return i.get(n)[t]},function(n){return function(o){var s,r=i.get(o);return n===r[t]?o:i.set(Object.assign({},r,(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;var N=function(t){return{show:function(i){var n="{";for(var o in t)$e.call(t,o)&&(n+=" ".concat(o,": ").concat(t[o].show(i[o]),","));return n.length>1&&(n=n.slice(0,-1)+" "),n+="}",n}}};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),at=t=>({show:i=>i==null?"<null>":t.show(i)}),Zi={show:t=>t!=null&&e.RA.isNonEmpty(t)?Yi.show(t):"<undefined>"},tn=O(N({localId:e.Str.Show,componentPath:Zi,sharedConfigurationModelId:at(e.Str.Show)})),en=e.Str.Show,nn=e.pipe(N({localId:e.Str.Show,configurationModel:e.Str.Show}),O,at),F=t=>e.pipe(N({kind:e.Str.Show,state:t}),O,at),ct={id:tn,key:en,type:e.Str.Show,sourceId:nn,isSatisfied:e.Bool.Show,canContributeToConfigurationSatisfaction:e.Bool.Show},on=N({...ct,decision:F(e.Bool.Show),nonOptimisticDecision:F(e.Bool.Show),possibleDecisionStates:O(e.RA.getShow(e.Bool.Show)),isPossibleDecisionStatesImmutable:e.Bool.Show,selection:e.Str.Show}),sn=N({...ct,decision:F(e.Num.Show),nonOptimisticDecision:F(e.Num.Show),selection:e.Str.Show,range:O(N({max:e.Num.Show,min:e.Num.Show})),decimalPlaces:e.Num.Show,isPossibleDecisionStatesImmutable:e.Bool.Show}),rn=N({...ct,decision:F(e.Str.Show),nonOptimisticDecision:F(e.Str.Show),possibleDecisionStates:O(e.RA.getShow(e.Str.Show)),isPossibleDecisionStatesImmutable:e.Bool.Show,selection:at(e.Str.Show),inclusion:e.Str.Show}),an=N({...ct,cardinality:O(N({upperBound:e.Num.Show,lowerBound:e.Num.Show})),values:e.RM.getShow(e.Str.Show,N({id:e.Str.Show,decision:F(e.Str.Show),nonOptimisticDecision:F(e.Str.Show),possibleDecisionStates:O(e.RA.getShow(e.Str.Show)),isPossibleDecisionStatesImmutable:e.Bool.Show}))}),cn={show:t=>l.match(t).with({type:a.Choice},an.show).with({type:a.Component},rn.show).with({type:a.Boolean},on.show).with({type:a.Numeric},sn.show).exhaustive()},un=e.flow(cn.show,e.I.map(t=>We.hash(t)));function ln(t){return{...t,hash:un(t)}}var dn=function(){return{concat:function(t,i){return He(t,i)}}},pn=function(){return{concat:dn().concat,empty:Rt}};function Nt(t){return e.MO.concatAll(pn())(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}),hn=e.Eq.struct({type:e.Str.Eq,includeConstraintsInConflictExplanation:e.Bool.Eq}),mn=e.Eq.struct({type:e.Str.Eq}),fn=e.Eq.union().with(t=>t.type==="Automatic",mn).with(t=>t.type==="Manual",hn),yn=e.Eq.struct({type:e.Str.Eq,conflictHandling:fn}),bn=e.Eq.struct({type:e.Str.Eq}),gn=e.Eq.union().with(t=>t.type==="DropExistingDecisions",yn).with(t=>t.type==="KeepExistingDecisions",bn),Sn=e.Eq.struct({type:e.Str.Eq,attributeId:g,state:e.Eq.eqNullable(e.Bool.Eq)}),En=e.Eq.struct({type:e.Str.Eq,attributeId:g,state:e.Eq.eqNullable(e.Num.Eq)}),In=e.Eq.struct({type:e.Str.Eq,attributeId:g,state:e.Eq.eqNullable(e.Str.Eq)}),wn=e.Eq.struct({type:e.Str.Eq,attributeId:g,choiceValueId:e.Str.Eq,state:e.Eq.eqNullable(e.Str.Eq)}),Pt=e.Eq.union().with(t=>t.type===a.Boolean,Sn).with(t=>t.type===a.Numeric,En).with(t=>t.type===a.Component,In).with(t=>t.type===a.Choice,wn),ce=e.pipe(e.Eq.struct({attributeId:g,choiceValueId:e.O.getEq(e.Str.Eq)}),e.Eq.contramap(t=>l.match(t).with({type:a.Choice},i=>({attributeId:i.attributeId,choiceValueId:e.some(i.choiceValueId)})).otherwise(i=>({attributeId:i.attributeId,choiceValueId:v})))),Cn=e.Eq.struct({mode:gn,decisions:e.RA.getUnsortedArrayEq(Pt)}),ue=e.Eq.struct({causedByDecisions:e.RA.getUnsortedArrayEq(Pt),solution:Cn}),le=e.Eq.struct({causedByCardinalities:e.RA.getUnsortedArrayEq(g),causedByRules:e.RA.getUnsortedArrayEq(Mt)}),An=e.Eq.struct({key:m,sourceId:e.Eq.struct({configurationModel:e.Str.Eq,localId:e.Str.Eq})}),tt=e.Eq.eqNullable(e.Eq.struct({state:e.Bool.Eq,kind:e.Str.Eq})),qn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,decision:tt,nonOptimisticDecision:tt}),et=e.Eq.eqNullable(e.Eq.struct({state:e.Num.Eq,kind:e.Str.Eq})),Rn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,decision:et,nonOptimisticDecision:et}),it=e.Eq.eqNullable(e.Eq.struct({state:e.Str.Eq,kind:e.Str.Eq})),Dn=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})),vn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,values:e.RA.getUnsortedArrayEq(e.Eq.struct({id:e.Str.Eq,decision:nt,nonOptimisticDecision:nt}))}),xn=e.Eq.union().with(t=>t.type===a.Boolean,qn).with(t=>t.type===a.Numeric,Rn).with(t=>t.type===a.Component,Dn).with(t=>t.type===a.Choice,vn),Nn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Bool.Eq),isPossibleDecisionStatesImmutable:e.Bool.Eq,selection:e.Str.Eq,isSatisfied:e.Bool.Eq}),Mn=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,isPossibleDecisionStatesImmutable:e.Bool.Eq,decimalPlaces:e.Num.Eq}),Pn=e.Eq.struct({type:e.Str.Eq,id:g,key:m,possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Str.Eq),isPossibleDecisionStatesImmutable:e.Bool.Eq,isSatisfied:e.Bool.Eq,inclusion:e.Str.Eq,selection:e.Eq.eqNullable(e.Str.Eq)}),kn=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)}))}),Bn=e.Eq.union().with(t=>t.type===a.Boolean,Nn).with(t=>t.type===a.Numeric,Mn).with(t=>t.type===a.Component,Pn).with(t=>t.type===a.Choice,kn),ut={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},On=e.Eq.struct({...ut,selection:e.Str.Eq,possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Bool.Eq),isPossibleDecisionStatesImmutable:e.Bool.Eq,decision:tt,nonOptimisticDecision:tt}),Fn=e.Eq.struct({...ut,selection:e.Str.Eq,range:e.Eq.struct({max:e.Num.Eq,min:e.Num.Eq}),decimalPlaces:e.Num.Eq,decision:et,nonOptimisticDecision:et,isPossibleDecisionStatesImmutable:e.Bool.Eq}),Tn=e.Eq.struct({...ut,inclusion:e.Str.Eq,selection:e.Eq.eqNullable(e.Str.Eq),possibleDecisionStates:e.RA.getUnsortedArrayEq(e.Str.Eq),isPossibleDecisionStatesImmutable:e.Bool.Eq,decision:it,nonOptimisticDecision:it}),Vn=e.Eq.struct({...ut,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),isPossibleDecisionStatesImmutable:e.Bool.Eq,decision:nt,nonOptimisticDecision:nt}))}),Et=e.Eq.union().with(t=>t.type===a.Boolean,On).with(t=>t.type===a.Numeric,Fn).with(t=>t.type===a.Component,Tn).with(t=>t.type===a.Choice,Vn),Wn=e.Eq.fromEquals((t,i)=>t.hash===i.hash);e.Eq.struct({isSatisfied:e.Bool.Eq,attributes:e.RM.getEq(m,Et)});e.Eq.struct({isSatisfied:e.Bool.Eq,attributes:e.RM.getEq(m,Wn)});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 jn=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})),Un=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)})))}),Ln=e.Eq.struct({attributeId:g,decisions:e.RA.getUnsortedArrayEq(g)}),_n=e.Eq.struct({attributes:e.RA.getEq(g)}),Hn=e.Eq.union().with(t=>t.type===L.Channel,e.Eq.struct({type:e.Str.Eq,channel:e.Str.Eq,deploymentName:e.Str.Eq})).with(t=>t.type===L.Package,e.Eq.struct({type:e.Str.Eq,configurationModelPackage:e.Eq.fromEquals(je.deepEqual)})),zn=e.Eq.struct({apiBaseUrl:e.Eq.eqNullable(e.Str.Eq),sessionInitialisationOptions:jn,configurationModelSource:Hn,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(Un),attributeRelations:e.Eq.eqNullable(e.RA.getUnsortedArrayEq(Ln)),wizardAttributeRelations:e.Eq.eqNullable(e.RA.getEq(_n)),disableConfigurationModelTrimming:e.Eq.eqNullable(e.Bool.Eq)});e.Eq.struct({isSatisfied:e.Bool.Eq,canContributeToSatisfaction:e.RA.getUnsortedArrayEq(m),meta:e.RM.getEq(m,An),decisions:e.RM.getEq(m,xn),consequences:e.RM.getEq(m,Bn)});const $n=e.Eq.struct({isSatisfied:e.Eq.eqNullable(e.Bool.Eq),attributes:e.Eq.struct({added:e.RA.getUnsortedArrayEq(Et),changed:e.RA.getUnsortedArrayEq(Et),removed:e.RA.getUnsortedArrayEq(g)})});let de="error";const Gn=P(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[]}}),Y=t=>(...i)=>{if(Gn(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}},H={setLogLevel:t=>{de=t},debug:Y("debug"),info:Y("info"),warn:Y("warning"),error:Y("error")},Qn=e.pipe(Qi(),Ji("attributes"));function kt(t){const i=e.pipe(t.attributes,e.RM.map(n=>Xi(n)?n:ln(n)));return{isSatisfied:t.isSatisfied,attributes:i}}function Kn(t){return e.pipe([...t.consequences.values()],e.RA.map(i=>l.match(i).returnType().with({type:a.Boolean},n=>({...n,canContributeToConfigurationSatisfaction:!1,decision:null,nonOptimisticDecision:null})).with({type:a.Numeric},n=>({...n,canContributeToConfigurationSatisfaction:!1,decision:null,nonOptimisticDecision:null})).with({type:a.Component},n=>({...n,canContributeToConfigurationSatisfaction:!1,decision:null,nonOptimisticDecision:null})).with({type:a.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,Ut(),e.RA.Foldable))})).exhaustive()),e.RA.map(i=>[i.key,i]),e.RM.fromFoldable(m,Ut(),e.RA.Foldable),i=>({attributes:i,isSatisfied:t.isSatisfied}),pe(t),kt)}function pe(t){const i=n=>z(Jn(o=>{const s=e.pipe(n,e.RA.elem(m)(o.key));return s!=o.canContributeToConfigurationSatisfaction?e.some({...o,canContributeToConfigurationSatisfaction:s}):v}));return n=>e.pipe({...n,isSatisfied:t.isSatisfied??n.isSatisfied},Xn([...(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 z(t){return e.pipe(Qn,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(()=>()=>{H.warn("Didn't found attribute while tying to update it. GlobalAttributeIdKey",t)}),e.O.getOrElse(()=>n))}function Jn(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 Xn(t){return e.pipe(t,e.RA.fromSingleOrArray,e.RA.map(Yn),z)}function Yn(t){return he(t.key,i=>"type"in t?i.type===a.Choice&&t.type===a.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(()=>()=>{H.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===a.Boolean&&t.type===a.Boolean?{...i,...t}:i.type===a.Numeric&&t.type===a.Numeric?{...i,...t}:i.type===a.Component&&t.type===a.Component?{...i,...t}:(H.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)),Zn={concat:(t,i)=>({...i,values:e.RA.getUnionSemigroup(fe).concat(i.values,t.values)})},to={concat:(t,i)=>({...i,values:e.RA.getUnionSemigroup(fe).concat(i.values,t.values)})},mt=rt(),ft=rt(),ye={concat:(t,i)=>l.match({x:t,y:i}).with({x:{type:a.Numeric},y:{type:a.Numeric}},({x:n,y:o})=>mt.concat(n,o)).with({x:{type:a.Boolean},y:{type:a.Boolean}},({x:n,y:o})=>mt.concat(n,o)).with({x:{type:a.Component},y:{type:a.Component}},({x:n,y:o})=>mt.concat(n,o)).with({x:{type:a.Choice},y:{type:a.Choice}},({x:n,y:o})=>Zn.concat(n,o)).otherwise(()=>i)},be={concat:(t,i)=>l.match({x:t,y:i}).with({x:{type:a.Numeric},y:{type:a.Numeric}},({x:n,y:o})=>ft.concat(n,o)).with({x:{type:a.Boolean},y:{type:a.Boolean}},({x:n,y:o})=>ft.concat(n,o)).with({x:{type:a.Component},y:{type:a.Component}},({x:n,y:o})=>ft.concat(n,o)).with({x:{type:a.Choice},y:{type:a.Choice}},({x:n,y:o})=>to.concat(n,o)).otherwise(()=>i)},eo=rt(),io=e.RM.getUnionSemigroup(m,rt()),no=e.RM.getUnionSemigroup(m,ye),oo=e.RM.getUnionSemigroup(m,be);function ge(t){return e.pipe(t,y,T)}function Se(t,i){const n=Ie(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),kt),rawData:s}}function so(t,i,n){const o=ro(n),s=Ie(i),r=Ee(t),c={isSatisfied:i.isConfigurationSatisfied,canContributeToSatisfaction:e.pipe(i.canAttributeContributeToConfigurationSatisfaction,e.RA.map(ge)),meta:o,decisions:r,consequences:s};return{configuration:Kn(c),rawData:c}}function Ee(t){const i=(c,u,d)=>e.pipe(c??[],e.RA.map(h=>({attributeId:y(h.attributeId),decision:h})),e.RA.map(({attributeId:h,decision:I})=>({id:h,key:T(h),...d(u(I),I)}))),n=i(t.booleanDecisions,ie,c=>({type:a.Boolean,decision:c,nonOptimisticDecision:c})),o=i(t.numericDecisions,ne,c=>({type:a.Numeric,decision:c,nonOptimisticDecision:c})),s=i(t.componentDecisions,oe,c=>({type:a.Component,decision:c,nonOptimisticDecision:c})),r=i(t.choiceValueDecisions,se,(c,u)=>({type:a.Choice,values:e.RA.of({id:u.choiceValueId,decision:c,nonOptimisticDecision:c})}));return e.pipe([...n,...o,...s,...r],e.RA.map(c=>[c.key,c]),e.RM.fromFoldable(m,ye,e.RA.Foldable))}function Ie(t){const i=(c,u)=>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),...u(h)}))),n=i(t.booleanConsequences,c=>({type:a.Boolean,isSatisfied:c.isSatisfied,possibleDecisionStates:c.possibleDecisionStates,isPossibleDecisionStatesImmutable:c.isPossibleDecisionStatesImmutable,selection:ht(c.selection)})),o=i(t.numericConsequences,c=>({type:a.Numeric,isSatisfied:c.isSatisfied,selection:ht(c.selection),range:{max:c.range.max,min:c.range.min},decimalPlaces:c.decimalPlaces,isPossibleDecisionStatesImmutable:c.isPossibleDecisionStatesImmutable})),s=i(t.componentConsequences,c=>({type:a.Component,isSatisfied:c.isSatisfied,possibleDecisionStates:e.pipe(c.possibleDecisionStates,e.RA.map(te)),isPossibleDecisionStatesImmutable:c.isPossibleDecisionStatesImmutable,inclusion:Li(c.inclusion),selection:c.selection?ht(c.selection):null})),r=i(t.choiceConsequences,c=>({type:a.Choice,isSatisfied:c.isSatisfied,cardinality:{lowerBound:c.cardinality.lowerBound,upperBound:c.cardinality.upperBound},values:e.pipe(c.values??[],e.RA.map(u=>({id:u.choiceValueId,possibleDecisionStates:e.pipe(u.possibleDecisionStates,e.RA.map(ee)),isPossibleDecisionStatesImmutable:u.isPossibleDecisionStatesImmutable})))}));return e.pipe([...n,...o,...s,...r],e.RA.map(c=>[c.key,c]),e.RM.fromFoldable(m,be,e.RA.Foldable))}function ro(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,eo,e.RA.Foldable))}function ao(t,i){const{configuration:n,rawData:o}=Se(t,i),s=_i(i.rejectedDecisions);return{configuration:n,rawData:o,result:{rejectedDecisions:s}}}function co(t,i){return n=>{if(n.type!=="PutManyDecisionsConflict")return v;const o=e.pipe(n.constraintExplanations??[],e.RA.map(xt)),s=Ae(n.decisionExplanations??[],t,i);return e.some({type:p.MakeManyDecisionsConflict,title:n.title??"",detail:n.detail??"",decisionExplanations:s,constraintExplanations:o})}}function uo(t){const i=we(t);return n=>({...i(n.decisionExplanations),...Ce(n.constraintExplanations)})}function we(t){const i=l.match(t).returnType().with({question:q.whyIsStateNotPossible,subject:S.boolean},n=>({type:a.Boolean,attributeId:n.attributeId,state:n.state})).with({question:q.whyIsStateNotPossible,subject:S.numeric},n=>({type:a.Numeric,attributeId:n.attributeId,state:n.state})).with({question:q.whyIsStateNotPossible,subject:S.component},n=>({type:a.Component,attributeId:n.attributeId,state:n.state})).with({question:q.whyIsStateNotPossible,subject:S.choiceValue},n=>({type:a.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(xt))}}function Ae(t,i,n){return e.pipe(t,e.RA.map(ji),e.RA.map(o=>{const s=e.pipe(o.causedByBooleanDecisions,e.RA.map(A=>({type:a.Boolean,attributeId:A.attributeId,state:null}))),r=e.pipe(o.causedByNumericDecisions,e.RA.map(A=>({type:a.Numeric,attributeId:A.attributeId,state:null}))),c=e.pipe(o.causedByComponentDecisions,e.RA.map(A=>({type:a.Component,attributeId:A.attributeId,state:null}))),u=e.pipe(o.causedByChoiceValueDecisions,e.RA.map(A=>({type:a.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(r),e.RA.concat(c),e.RA.concat(u)),I=e.RA.getUnionSemigroup(ce).concat(h,e.RA.fromSingleOrArray(i));return{causedByDecisions:d,solution:{mode:n,decisions:I}}}))}function qe(t,i){return e.pipe({isSatisfied:i.isSatisfied??t.isSatisfied,canContributeToSatisfaction:i.canContributeToSatisfaction??t.canContributeToSatisfaction,meta:i.meta?io.concat(t.meta,i.meta):t.meta,decisions:i.decisions?no.concat(t.decisions,i.decisions):t.decisions,consequences:i.consequences?oo.concat(t.consequences,i.consequences):t.consequences},lo)}function lo(t){const i=e.pipe(t.decisions,e.RM.filterMap(n=>n.type===a.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):v));return{...t,decisions:i}}function po(t){return[...t.decisions.values()].some(i=>{var n;return i.type===a.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 ho(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=>l.match(n).returnType().with({type:a.Boolean},o=>i(o,o.decision,{})).with({type:a.Numeric},o=>i(o,o.decision,{})).with({type:a.Component},o=>i(o,o.decision,{})).with({type:a.Choice},o=>e.pipe(o.values,e.RA.chain(s=>i(o,s.decision,{choiceValueId:s.id})))).exhaustive()))}function mo(t){return e.pipe(t.decisions,e.RM.values(e.Ord.trivial),e.RA.chain(Re))}function Re(t){return l.match(t).returnType().with({type:a.Boolean},e.flow(fo,e.RA.fromOption)).with({type:a.Numeric},e.flow(yo,e.RA.fromOption)).with({type:a.Component},e.flow(bo,e.RA.fromOption)).with({type:a.Choice},go).exhaustive()}function fo(t){var i;return((i=t.decision)==null?void 0:i.kind)===E.Explicit?e.some({type:a.Boolean,attributeId:t.id,state:t.decision.state}):v}function yo(t){var i;return((i=t.decision)==null?void 0:i.kind)===E.Explicit?e.some({type:a.Numeric,attributeId:t.id,state:t.decision.state}):v}function bo(t){var i;return((i=t.decision)==null?void 0:i.kind)===E.Explicit?e.some({type:a.Component,attributeId:t.id,state:t.decision.state}):v}function go(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:a.Choice,attributeId:t.id,choiceValueId:i.id,state:i.decision.state})))}function So(t,i){const n=i.decisions.get(T(t.attributeId)),o=n?Re(n):[];return e.pipe(o,e.RA.findFirst(r=>ce.equals(r,t)),e.O.match(()=>t.state==null,r=>Pt.equals(r,t)))}function Eo(t,i){return e.RA.isEmpty(t)&&i==="KeepExistingDecisions"}const De={Accept:"application/json"};function ve(t){const i=G(t.apiBaseUrl),n=(o,s)=>x(()=>o(Ci(t),{headers:{...De,...s??{}}}));return e.pipe(l.match(t.sessionInitialisationOptions).with({accessToken:l.P.string},o=>n(i.session.sessionPost,{Authorization:`Bearer ${o.accessToken}`})).with({sessionCreateUrl:l.P.string},o=>n(Ii(o.sessionCreateUrl))).exhaustive(),e.TE.map(o=>({sessionContext:t,sessionId:o.sessionId})),e.TE.chain(o=>{const s=x(()=>i.decision.decisionGetAllDecisions({headers:U(o)})),r=x(()=>i.consequence.consequenceGet({headers:U(o)})),c=o.sessionContext.provideSourceId??!1?x(()=>i.meta.metaGet({headers:U(o)})):e.TE.right(null);return e.pipe(zi(e.TE.ApplicativePar)({decisions:s,consequences:r,meta:c}),e.TE.map(u=>so(u.decisions,u.consequences,u.meta)),e.TE.map(u=>({...o,configuration:u.configuration,configurationRawData:u.rawData})))}))}function xe(t,i){const n=Ai(t,i);return o=>{if(Eo(t,i.type))return e.TE.right({sessionState:o,result:{rejectedDecisions:[]}});const s=G(o.sessionContext.apiBaseUrl);return e.pipe(x(()=>s.decision.decisionPutMany(n,{headers:U(o)}),co(t,i)),e.TE.map(r=>e.pipe(ao(o.configuration,r),e.I.map(c=>({sessionState:{...o,configurationRawData:qe(o.configurationRawData,c.rawData),configuration:c.configuration},result:c.result})))))}}function Io(t){const i=wi(t);return n=>{if(So(t,n.configurationRawData))return e.TE.right(n);const o=G(n.sessionContext.apiBaseUrl);return e.pipe(x(()=>o.decision.decisionPutDecision(i,{headers:U(n)})),e.TE.map(s=>{const{configuration:r,rawData:c}=Se(n.configuration,s);return{...n,configuration:r,configurationRawData:qe(n.configurationRawData,c)}}))}}function wo(t,i){const n=(s,r,c,u,d)=>{const h=r(s);return(I,A)=>l.match(i).with("decisions",()=>e.pipe(x(()=>c(I.explain)(h,A)),e.TE.map(we(s)))).with("constraints",()=>e.pipe(x(()=>u(I.explain)(h,A)),e.TE.map(Ce))).with("full",()=>e.pipe(x(()=>d(I.explain)(h,A)),e.TE.map(uo(s)))).exhaustive()},o=l.match(t).with({question:q.whyIsNotSatisfied},s=>n(s,qi,r=>r.explainWhyNotSatisfiedDecisions,r=>r.explainWhyNotSatisfiedRules,r=>r.explainWhyNotSatisfied)).with({question:q.whyIsStateNotPossible},s=>n(s,Ri,r=>r.explainWhyStateNotPossibleDecisions,r=>r.explainWhyStateNotPossibleRules,r=>r.explainWhyStateNotPossible)).exhaustive();return s=>{const r=G(s.sessionContext.apiBaseUrl);return o(r,{headers:U(s)})}}function Ne(t){const i=G(t.sessionContext.apiBaseUrl);return x(()=>i.session.sessionDelete(t.sessionId))}function Co(t){return i=>Me(i,t)}function Me(t,i){return t.sessionId&&Ne({...t,sessionId:t.sessionId})(),e.pipe({...t