import{d as G}from"./chunk-FTLECNUN.js";import{b as P}from"./chunk-I6XJVXQ2.js";import{c as L,d as w}from"./chunk-TY5UPKV5.js";import{a as j}from"./chunk-5L2Z4GZW.js";import{M as _,la as $}from"./chunk-XS4DMB2U.js";import{f as F,i as d}from"./chunk-RN3RVYIR.js";import{s as q}from"./chunk-VYUKN3XQ.js";import{c as x}from"./chunk-AYHVL37M.js";import{h as B}from"./chunk-KXVCY5JT.js";import{L as b,Na as U,O as A,P as v,Ta as R,ca as M,l as u,wa as S}from"./chunk-XNQ3RS5P.js";var N=function(e){return e.CanBuy="CAN_BUY",e.CannotBuy="CANNOT_BUY",e}(N||{}),C=function(e){return e.Basic="BASIC",e.Premium="PREMIUM",e}(C||{}),Z=function(e){return e.Forbidden="FORBIDDEN",e.ImeiNotEligible="IMEI_NOT_ELIGIBLE",e.ImeiOrSerialNoNotValid="IMEI_OR_SERIAL_NO_NOT_VALID",e.InvalidProductDataFromTgw="INVALID_PRODUCT_DATA_FROM_TGW",e.NoEligibleCategories="NO_ELIGIBLE_CATEGORIES",e.NoExchangeRateAvailable="NO_EXCHANGE_RATE_AVAILABLE",e.NoInsuranceFound="NO_INSURANCE_FOUND",e.NoInsuranceTierAvailableToBuy="NO_INSURANCE_TIER_AVAILABLE_TO_BUY",e.NoRecentBoughtDevices="NO_RECENT_BOUGHT_DEVICES",e.NoRequestedCategories="NO_REQUESTED_CATEGORIES",e.NoSaleProductData="NO_SALE_PRODUCT_DATA",e.RequestedTierNotAvailableForPurchase="REQUESTED_TIER_NOT_AVAILABLE_FOR_PURCHASE",e}(Z||{}),V,T=d(V||(V=u(["\n    fragment Money on Money {\n  currency\n  displayValue\n  value\n  valueWithoutVat\n}\n    "]))),H,ee=d(H||(H=u(["\n    fragment InsuranceProductOfferedTierItem on InsuranceProductOfferedTierItem {\n  tier\n  startingPrice {\n    ...Money\n  }\n  state\n  isRequested\n}\n    ",""])),T),Y,te=d(Y||(Y=u(["\n    fragment InsuranceOption on InsuranceOption {\n  insuranceId\n  tier\n  fee {\n    ...Money\n  }\n  state\n}\n    ",""])),T),Q,y=d(Q||(Q=u(["\n    fragment InsuranceNotSellableReason on InsuranceNotSellableReason {\n  reason\n  message\n}\n    "]))),k,re=d(k||(k=u(["\n    fragment InsurableProductItem on InsurableProductItem {\n  imei\n  oaCode\n  categoryId\n  displayName\n  imageHref\n  state\n  standardPriceNoVat {\n    ...Money\n  }\n  options {\n    ...InsuranceOption\n  }\n  notSellableReason {\n    ...InsuranceNotSellableReason\n  }\n}\n    ","\n","\n",""])),T,te,y),z,oe=d(z||(z=u(["\n    fragment InsuranceProductItem on InsuranceProductItem {\n  deviceCategoryId\n  requestedTier\n  name\n  insuranceId\n  offeredTiers {\n    ...InsuranceProductOfferedTierItem\n  }\n  insurableProducts {\n    ...InsurableProductItem\n  }\n  price {\n    ...Money\n  }\n  notSellableReason {\n    ...InsuranceNotSellableReason\n  }\n}\n    ","\n","\n","\n",""])),ee,re,T,y),W,ne=d(W||(W=u(["\n    fragment CategoryMappedProducts on InsuranceProductCategorizedDetails {\n  categoryId\n  state\n  product {\n    ...InsuranceProductItem\n  }\n}\n    ",""])),oe),X,se=d(X||(X=u(["\n    fragment InsuranceProductPersonalizedDetails on InsuranceProductPersonalizedDetails {\n  categoryMappedProducts {\n    ...CategoryMappedProducts\n  }\n  notSellableReason {\n    ...InsuranceNotSellableReason\n  }\n}\n    ","\n",""])),ne,y),J,K=d(J||(J=u(["\n    query GetInsuranceProductCustomDetails($request: InsuranceProductDetailsRequest) {\n  getInsuranceProductCustomDetails(request: $request) {\n    ...InsuranceProductPersonalizedDetails\n  }\n}\n    ",""])),se);var D=function(e){return e.Custom="custom",e}(D||{});var ae=function(e){return e.Phone="Telefoane",e.Tablet="Tablete",e.Smartwatch="Smartwatches",e.ConnectedObject="Obiecte conectate",e}(ae||{}),ie=function(e){return e.Phone="telefoane",e.Tablet="tablete",e.Smartwatch="smartwatches",e.ConnectedObject="obiecte-conectate",e}(ie||{});var Be=(()=>{let I=class I{constructor(){this.apollo=R(F),this.store=R(q),this.httpClient=R(B),this.insuranceCategoryOfferingsUrl=x.getInsuranceCategoryApi(),this.REQUEST_TIMEOUT=3e4,this.RETRY_COUNT=2}saveUserAgreement(t,r){let o=L(r.gdprConsents);this.store.dispatch(w({insuranceTermsAgreed:t,isAbove16:r.isAbove16,hasPaymentCommitment:r.hasPaymentCommitment,keepIdCard:r.keepIdCard,gdprConsents:o,notificationChannel:r.notificationChannel}))}fetchCategoryOfferings(){return this.httpClient.get(this.insuranceCategoryOfferingsUrl,{withCredentials:!0,headers:{Accept:"application/json","Content-Type":"application/json"}}).pipe(A(this.REQUEST_TIMEOUT),S(this.RETRY_COUNT),M(this.handleError))}buildInsuranceProductDetailsRequest(t,r,o,a,n,s,i){return r||console.error("Active MSISDN is required to build the insurance product details request."),{deviceCategoryId:void 0,deviceImei:t===D.Custom?n:void 0,deviceOaCode:s,msisdn:r,orderId:i,productCategoryIds:o?[o]:[],tier:a}}getInsuranceProductCustomDetails(t){return this.apollo.use(j).query({query:K,variables:{request:t},errorPolicy:"all",fetchPolicy:"cache-first"}).pipe(A(this.REQUEST_TIMEOUT),S(this.RETRY_COUNT),v(({data:r,errors:o,loading:a})=>{if(o&&o.length>0)return{success:!1,errors:o.map(i=>{var m,l;return{message:i.message,code:((m=i.extensions)==null?void 0:m.code)||"GRAPHQL_ERROR",field:((l=i.path)==null?void 0:l.join("."))||void 0}}),metadata:{requestId:this.generateRequestId(),timestamp:new Date().toISOString()}};let n=r==null?void 0:r.getInsuranceProductCustomDetails;return n?{success:!0,data:{getInsuranceProductCustomDetails:n},metadata:{requestId:this.generateRequestId(),timestamp:new Date().toISOString()}}:{success:!1,errors:[{message:"No product details returned from server",code:"EMPTY_RESPONSE"}],metadata:{requestId:this.generateRequestId(),timestamp:new Date().toISOString()}}}))}processInsuranceProductDetails(t){if(!t)return{categoryMappedProducts:[],notSellableReason:null,isAvailable:!1,availableProducts:[]};let r=(t.categoryMappedProducts||[]).filter(n=>n!=null),o=r.filter(n=>n.state===N.CanBuy),a=t.notSellableReason||null;return{categoryMappedProducts:r,notSellableReason:a,isAvailable:o.length>0&&!a,availableProducts:o}}addInsurance(t,r,o,a,n){var f,c;if(!r||!o){console.error("Missing required fields: selectedProduct, selectedItem, or activeMsisdn");return}let i=t===D.Custom?a:r.imei,m=(c=(f=r.options)==null?void 0:f[0])==null?void 0:c.insuranceId,l=n===C.Basic?_.Basic:_.Premium,g=this.getInsuranceTerm(),O=this.getProductDetails(r,i);if(!m){console.error("Missing insuranceId");return}let h={productDetails:O,term:g,insuranceId:m,insuranceType:l,msisdn:o};this.dispatchAddInsuranceProduct(h)}calculateLoggedInInsurableProduct(t,r){var o,a;if(r===C.Basic){let n=t.options||[],s=P(n);return((o=s==null?void 0:s.fee)==null?void 0:o.value)||0}else{let n=t.options||[],s=P(n);return((a=s==null?void 0:s.fee)==null?void 0:a.value)||0}}calculateLoggedInItemPrice(t,r){var o,a,n,s,i,m,l,g,O,h;if(r===C.Basic){let f=((o=t.options)==null?void 0:o.BASIC)||((s=(n=(a=t.children)==null?void 0:a.find(p=>{var E;return((E=p==null?void 0:p.options)==null?void 0:E.BASIC)&&p.options.BASIC.length>0}))==null?void 0:n.options)==null?void 0:s.BASIC)||[],c=P(f);return((i=c==null?void 0:c.optionFee)==null?void 0:i.value)||0}else{let f=((m=t.options)==null?void 0:m.PREMIUM)||((O=(g=(l=t.children)==null?void 0:l.find(p=>{var E;return((E=p==null?void 0:p.options)==null?void 0:E.PREMIUM)&&p.options.PREMIUM.length>0}))==null?void 0:g.options)==null?void 0:O.PREMIUM)||[],c=P(f);return((h=c==null?void 0:c.optionFee)==null?void 0:h.value)||0}}getProductDetails(t,r){return{oaCode:t.oaCode||"",imei:r||"",categoryId:t.categoryId||1,thumbnail:t.imageHref||""}}getInsuranceTerm(t=$.Months,r=24){return{unit:t,value:r}}dispatchAddInsuranceProduct(t){this.store.dispatch(G({insurance:t}))}handleError(t){return t.status===0?console.error("An error occurred:",t.error):console.error("Backend returned code ".concat(t.status,", body was: "),t.error),b(()=>new Error("Something bad happened; please try again later."))}generateRequestId(){return"req_".concat(Date.now(),"_").concat(Math.random().toString(36).substr(2,9))}};I.\u0275fac=function(r){return new(r||I)},I.\u0275prov=U({token:I,factory:I.\u0275fac,providedIn:"root"});let e=I;return e})();export{N as a,C as b,Z as c,ae as d,ie as e,D as f,Be as g};