import{d as L}from"./chunk-5YSUPGXK.js";import{Pf as q,Qc as U,Sf as g,U as o,V as p,X as r,_b as C,aa as I,ac as D,hd as a,id as d,pf as M,qf as u,x as h}from"./chunk-O6GKIPTD.js";var l=(()=>{class e{constructor(t){this.restService=t}getUniqueIDConfigurations(t){let i=new D;return i=i.append("packageType",t),t!==d.CONTAINER&&(i=i.append("businessUnitID",M.getBusinessUnit().id)),this.restService.get(U.UNIQUE_ID_CONFIGURATIONS,i)}static{this.\u0275fac=function(i){return new(i||e)(r(L))}}static{this.\u0275prov=o({token:e,factory:e.\u0275fac})}}return e})();var f=(()=>{class e{constructor(t){this.uniqueIDConfigurations=t}getUniqueIDConfigurations(t){return this.uniqueIDConfigurations.getUniqueIDConfigurations(t)}static{this.\u0275fac=function(i){return new(i||e)(r(l))}}static{this.\u0275prov=o({token:e,factory:e.\u0275fac})}}return e})();var S=(()=>{class e{static{this.\u0275fac=function(i){return new(i||e)}}static{this.\u0275mod=I({type:e})}static{this.\u0275inj=p({providers:[f,l],imports:[C]})}}return e})();var m=(()=>{class e{constructor(t,i){this.uniqueIDConfigurationsFacade=t,this.translateService=i,this.uniqueIDConfigurations=new Map,this.minLength=new Map,this.allowedLengths=new Map}loadUniqueIDConfigurations(t){return new Promise((i,n)=>{h(t.map(s=>this.uniqueIDConfigurationsFacade.getUniqueIDConfigurations(s))).subscribe({next:s=>{this.buildConfigurationMapsPerPackageType(s),i(this.uniqueIDConfigurations)},error:s=>{n(s)}})})}buildConfigurationMapsPerPackageType(t){t.forEach(i=>{if(u.isNullOrUndefined(i)||i.length===0)return;let n=i[0].packageType;this.uniqueIDConfigurations.set(n,i),this.allowedLengths.set(n,this.calculateAllowedLenghts(i)),this.minLength.set(n,this.calculateMinLength(i,this.allowedLengths.get(n)))})}calculateAllowedLenghts(t){return new Set(t.map(i=>i.length))}calculateMinLength(t,i){return Math.min.apply(null,Array.from(i))}getUniqueIDConfigurations(t){return this.uniqueIDConfigurations.get(t)}getMinLength(t){return this.minLength.get(t)}getAllowedLengths(t){return this.allowedLengths.get(t)}fillLeadingZeros(t,i){let n=this.getMinLength(i);return t.length>0&&t.length<n&&(t=u.fillLeadingZeros(t,n)),t}validateIDCode(t,i){if(!this.existsIDCodeConfiguration(i))return this.translateService.instant("MSG_NO_ID_CODE_CONFIGURATION_FOUND");if(t=this.fillLeadingZeros(t,i),!this.isIdCodeLengthValid(t,i)){let n=Array.from(this.getAllowedLengths(i));return this.translateService.instant("MSG_ID_CODE_LENGTH_NOT_CORRECT",{allowedIDCodeLengths:n})}return this.existsMatchingIDCodeConfiguration(t,i)?null:this.translateService.instant("MSG_NO_MATCHING_ID_CODE_CONFIGURATION",{idCode:t})}existsIDCodeConfiguration(t){let i=this.getUniqueIDConfigurations(t);return!u.isNullOrUndefined(i)&&i.length!==0}isIdCodeLengthValid(t,i){return this.getUniqueIDConfigurations(i).some(n=>n.length===t.length)}existsMatchingIDCodeConfiguration(t,i){return this.getUniqueIDConfigurations(i).filter(n=>n.length===t.length).some(n=>this.idCodeMatchesConfiguration(n,t))}idCodeMatchesConfiguration(t,i){if(i<t.minimumRange||i>t.maximumRange)return!1;switch(t.format){case a.NUMERIC:return g.isPositiveWholeNumber(i);case a.HEXA:return g.isHexaDecimal(i);case a.ALPHANUMERIC:return u.isAlphaNumeric(i);case a.ASCII:return!0;default:return!1}}static{this.\u0275fac=function(i){return new(i||e)(r(f),r(q))}}static{this.\u0275prov=o({token:e,factory:e.\u0275fac})}}return e})();var A=(()=>{class e{constructor(t){this.uniqueIDConfigurationsManager=t}resolve(t){return this.uniqueIDConfigurationsManager.loadUniqueIDConfigurations(t)}static{this.\u0275fac=function(i){return new(i||e)(r(m))}}static{this.\u0275prov=o({token:e,factory:e.\u0275fac})}}return e})();export{f as a,S as b,m as c,A as d};
