(function() {
const defaultCurrencyOptions = Object.freeze({precision: 2, truncEnabled: false});
const defaultCurrencyType = Object.freeze('USD');
const defaultDecimalOptions = Object.freeze({precision: 2, truncEnabled: true});
const defaultExchangeRateOptions = Object.freeze({precision: 6, truncEnabled: false});
const percentageOptions = Object.freeze({precision: 4, truncEnabled: false});
"use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){if(b&&("object"===_typeof(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}var Condition=/*#__PURE__*/function(){function a(b){_classCallCheck(this,a),this.expression=assertNotNull(b,"expression")}return _createClass(a,[{key:"IsSatisfied",value:function IsSatisfied(a,b){return this.expression(a,b)}}]),a}(),CompositeCondition=/*#__PURE__*/function(a){function b(a,d){var e;return _classCallCheck(this,b),e=c.call(this,a),e.conditions=assertNotNull(d,"conditions"),e}_inherits(b,a);var c=_createSuper(b);return b}(Condition),ProtectTypeID="protect",RateRule=/*#__PURE__*/function(){function a(){_classCallCheck(this,a)}return _createClass(a,[{key:"Rate",value:// eslint-disable-next-line class-methods-use-this
function Rate(a,b){throw assertNotNull(a),assertNotNull(b),new Error("this method must be overridden")}}],[{key:"defaultGetMoneyWrapper",value:function defaultGetMoneyWrapper(a){var b;return newMoneyWrapper(a,null===a||void 0===a||null===(b=a.CartInfo)||void 0===b?void 0:b.CoveredAmount,"/CartInfo/CoveredAmount")}},{key:"ValidateAgreement",value:function ValidateAgreement(a,b,c){assertNotNull(b,"ValidateAgreement.input"),assertCoverageAgreementIsValid(b.CoverageAgreement);var d=Date.now(),e=b.CoverageAgreement;if(e.TypeID){var f,g;if("enabled"!==e.State)return!1;if(null!==(f=e.Validity)&&void 0!==f&&f.ValidFrom){var h=new Date(Date.parse(e.Validity.ValidFrom));if(isNaN(h.getTime()))throw new Error("ValidateAgreement: Invalid ValidFrom=[".concat(e.Validity.ValidFrom,"] date format"));if(0>d-h)return!1;// unavailable => before valid_from
}if(null!==(g=e.Validity)&&void 0!==g&&g.ValidTo){var i=new Date(Date.parse(e.Validity.ValidTo));if(isNaN(i.getTime()))throw new Error("ValidateAgreement: Invalid ValidTo=[".concat(e.Validity.ValidTo,"] date format"));if(0>=i-d)return!1;// expired, after valid_to
}if(e.TypeID!==ProtectTypeID)return!0;// it is allowed for base agreements
}else if(!e.IsProtectEnabled)return!1;// If in covered is below lower limit or greater than upper limit returns no coverage
return!(e.LowerLimit&&c.Amount.LessThan(e.LowerLimit))&&!(e.UpperLimit&&c.Amount.GreaterThan(e.UpperLimit))}},{key:"ValidateIfInputCanBeRated",value:function ValidateIfInputCanBeRated(a,b){return assertNotNull(b,"input"),assertNotNull(b.CartInfo,"input.CartInfo"),!0}},{key:"ValidateIfInputCanBeRatedWithMoneyWrapper",value:function ValidateIfInputCanBeRatedWithMoneyWrapper(b,c,d){assertNotNull(c,"input"),assertNotNull(d,"moneyWrapper"),assertCurrencyIsValid(d.originalAmount,"moneyWrapper.originalAmount"),assertCurrencyIsValid(d.amountUSD,"moneyWrapper.amountUSD");var e=d.amountUSD;return!!e.Amount.IsPositive&&a.ValidateAgreement(b,c,e)}}]),a}(),AndCondition=/*#__PURE__*/function(a){function b(a){var d;return _classCallCheck(this,b),d=c.call(this,function(a,b){return d.conditions.every(function(c){return c.IsSatisfied(a,b)})},a)}_inherits(b,a);var c=_createSuper(b);return b}(CompositeCondition);function isNull(a){return a===void 0||null===a}function assertNotNull(a,b){if(isNull(a))throw new Error("object [".concat(b,"] is mandatory"));return a}function isValidDate(a){return!Number.isNaN(Date.parse(a))}var CartInfo=/*#__PURE__*/function(){function a(b){var c=b.coveredAmount,d=void 0===c?new Currency:c,e=b.coveredWithDiscounts,f=void 0===e?new Currency:e;_classCallCheck(this,a),this.coveredAmount=d,this.coveredAmountUSD=null,this.coveredWithDiscounts=assertCurrencyIsValid(f,"CartInfo.coveredWithDiscounts")}return _createClass(a,[{key:"CoveredWithDiscounts",get:function get(){return this.coveredWithDiscounts}},{key:"CoveredAmount",get:function get(){return this.coveredAmount}},{key:"CoveredAmountInUSD",value:function CoveredAmountInUSD(a,b){if(null===this.coveredAmountUSD)if("USD"===this.coveredAmount.Currency)this.coveredAmountUSD=this.coveredAmount;else{var c=b.FindExchangeRate(this.coveredAmount.Type,defaultCurrencyType);this.coveredAmountUSD=this.coveredAmount.Exchange(c)}return this.coveredAmountUSD}}]),a}(),namedRateRuleApplied=6,ConditionalRateRule=/*#__PURE__*/function(a){function b(a){var d,e=a.condition,f=void 0===e?null:e,g=a.rateRule,h=a.fallbackRateRule,i=void 0===h?NoCoverageRateRule:h,j=a.name;return _classCallCheck(this,b),d=c.call(this),d.name=j,d.condition=f,d.rateRule=assertNotNull(g,"RateRule"),d.fallbackRateRule=assertNotNull(i,"FallbackRateRule"),d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"Rate",value:function Rate(a,b){if(!RateRule.ValidateIfInputCanBeRated(a,b))return NoCoverageResult;if(isNull(this.condition)||this.condition.IsSatisfied(a,b)){var c=this.rateRule.Rate(a,b);return c&&this.name&&(!c.notes&&(c.notes=[]),c.notes.push({reason:namedRateRuleApplied,comment:this.name})),c}return this.fallbackRateRule.Rate(a,b)}}]),b}(RateRule);// assertOldAgreementIsValid validates the Protect product agreement available BEFORE V2 support for Returns/Carbon
function assertOldAgreementIsValid(b){if(isNull(b))throw new Error("invalid null CoverageAgreement");if(isNull(b.IsProtectEnabled))throw new Error("given CoverageAgreement does not have the \"IsProtectEnabled\" property");if("boolean"!=typeof b.IsProtectEnabled)throw new Error("CoverageAgreement.IsProtectEnabled=[".concat(b.IsProtectEnabled,"] is not a boolean"));return assertDecimalIsValid(b.UpperLimit,"CoverageAgreement.UpperLimit"),assertDecimalIsValid(b.LowerLimit,"CoverageAgreement.LowerLimit"),b}// assertBaseAgreementIsValid validates simple product agreements based on a single state/validity
function assertBaseAgreementIsValid(b){if(isNull(b))throw new Error("invalid null CoverageAgreement");if(isNull(b.State))throw new Error("given BaseAgreement does not have the \"State\" property");if("string"!=typeof b.State)throw new Error("BaseAgreement.State=[".concat(b.State,"] is not a string"));if(!isNull(b.Validity)){if(!isNull(b.Validity.ValidFrom)&&!isValidDate(b.Validity.ValidFrom))throw new Error("BaseAgreement.Validity.ValidFrom=[".concat(b.Validity.ValidFrom,"] is not a date"));if(!isNull(b.Validity.ValidTo)&&!isValidDate(b.Validity.ValidTo))throw new Error("BaseAgreement.Validity.ValidTo=[".concat(b.Validity.ValidTo,"] is not a date"))}return b}// assertProtectAgreementIsValid validates the Protect product agreement (V2 with support for Returns/Carbon)
function assertProtectAgreementIsValid(b){return assertBaseAgreementIsValid(b),assertDecimalIsValid(b.UpperLimit,"ProtectAgreement.UpperLimit"),assertDecimalIsValid(b.LowerLimit,"ProtectAgreement.LowerLimit"),b}function assertCoverageAgreementIsValid(b){if(isNull(b))throw new Error("invalid null CoverageAgreement");return isNull(b.TypeID)?assertOldAgreementIsValid(b):"protect"===b.TypeID?assertProtectAgreementIsValid(b):assertBaseAgreementIsValid(b)}function assertCurrencyIsValid(a,b){var c=b||"unknown";if(isNull(a))throw new Error("".concat(c,": invalid null currency"));if(isNull(a.currencyType))throw new Error("".concat(c,": given currency does not have the \"currencyType\" property"));return assertDecimalIsValid(a.currencyValue,c),a}var Currency=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{type:defaultCurrencyType,value:new Decimal,currency:null,amount:null},c=b.type,d=void 0===c?defaultCurrencyType:c,e=b.value,f=void 0===e?new Decimal:e,g=b.currency,h=void 0===g?null:g,i=b.amount,j=void 0===i?null:i;_classCallCheck(this,a);var k=f;null!==j&&(k=j);var l=d;null!==h&&(l=h),k instanceof Decimal||(k=new Decimal(k,_objectSpread({},defaultCurrencyOptions))),this.currencyType=l,this.currencyValue=k}return _createClass(a,[{key:"Type",get:function get(){return this.currencyType}},{key:"Currency",get:function get(){return this.currencyType}},{key:"Amount",get:function get(){return this.currencyValue}},{key:"HasTheSameTypeAs",value:function HasTheSameTypeAs(a){return a===this.currencyType}},{key:"HasTheSameTypeAsTheOther",value:function HasTheSameTypeAsTheOther(a){return this.HasTheSameTypeAs(a.currencyType)}},{key:"Exchange",value:function Exchange(b){if(this.HasTheSameTypeAs(b.FromCurrencyType))return new a({type:b.ToCurrencyType,value:this.Amount.Multiply(b.Rate,{resultOptions:defaultCurrencyOptions,truncEnabled:defaultExchangeRateOptions.truncEnabled})});if(this.HasTheSameTypeAs(b.ToCurrencyType))return new a({type:b.FromCurrencyType,value:this.Amount.Divide(b.Rate,{resultOptions:defaultCurrencyOptions,truncEnabled:defaultExchangeRateOptions.truncEnabled})});throw new Error("exchange rate cannot be used with currency type: ".concat(this,", ").concat(b))}}]),a}();function assertDecimalIsValid(a,b){if(isNull(a))throw new Error("".concat(b,": decimal is null"));if(isNull(a.value))throw new Error("".concat(b,": given decimal does not have the \"value\" property"));if("number"!=typeof a.value)throw new Error("".concat(b,": decimal.value=[").concat(a.value,"] is not a number"));if(isNull(a.options))throw new Error("".concat(b,": given decimal does not have the \"options\" property"));if(isNull(a.options.precision))throw new Error("".concat(b,": given decimal.options does not have the \"precision\" property"));if("number"!=typeof a.options.precision)throw new Error("".concat(b,": decimal.options.precision=[").concat(a.options.precision,"] is not a number"));if(isNull(a.options.truncEnabled))throw new Error("".concat(b,": given decimal.options does not have the \"truncEnabled\" property"));if("boolean"!=typeof a.options.truncEnabled)throw new Error("".concat(b,": decimal.options.precision=[").concat(a.options.truncEnabled,"] is not a boolean"));return a}var Decimal=/*#__PURE__*/function(){var a=Math.pow,b=Math.trunc,c=Number.isNaN;function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0,b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:Object.freeze(defaultDecimalOptions);if(_classCallCheck(this,d),!0===b.asIs){var c=d.assertOptionsIsValid(b);this.value=a,this.options={precision:c.precision,truncEnabled:c.truncEnabled}}else if("number"==typeof a)this.fromNumber(a,b);else if("string"==typeof a)this.fromString(a,b);else throw new Error("invalid data type=".concat(_typeof(a)," to create a decimal"))}return _createClass(d,[{key:"Value",get:function get(){return this.value}},{key:"IsZero",get:function get(){return 0===this.value}},{key:"IsNegative",get:function get(){return 0>this.value}},{key:"IsPositive",get:function get(){return 0<this.value}/**
   * Multiply expects an optional OperationOptions with the following properties:
   *
   * {   //specifies the options for the decimal created by Multiply
   *     resultOptions Options // same as provided in the constructor
   *     //specifies the truncation behavior
   *     truncEnabled
   * }
   */},{key:"Multiply",value:function Multiply(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c=_objectSpread({},this.options),e=this.options.truncEnabled;this.options.precision<a.options.precision&&(c.precision=a.options.precision),isNull(b)||(e=b.truncEnabled,c=d.assertOptionsIsValid(b.resultOptions));var f=d.adjustPrecision(a.value*this.value,this.options.precision+a.options.precision,c.precision,e);return new d(f,_objectSpread(_objectSpread({},c),{},{asIs:!0}))}},{key:"Divide",value:function Divide(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,e=_objectSpread({},this.options),f=this.options.truncEnabled;this.options.precision<a.options.precision&&(e.precision=a.options.precision),isNull(c)||(f=c.truncEnabled,e=d.assertOptionsIsValid(c.resultOptions));var g,h;if(f)g=d.adjustPrecision(this.value,this.options.precision,e.precision+a.options.precision,f),h=b(g/a.value);else{g=d.adjustPrecision(this.value,this.options.precision,e.precision+a.options.precision+1,f);var i=d.roundValue(0>a.value);h=b((g/a.value+i)/10)}return new d(h,_objectSpread(_objectSpread({},e),{},{asIs:!0}))}},{key:"Compare",value:function Compare(a){var b=0;return this.normalizeWith(a,function(a,c){b=a-c}),b}},{key:"Equals",value:function Equals(a){return 0===this.Compare(a)}},{key:"LessThan",value:function LessThan(a){return 0>this.Compare(a)}},{key:"LessThanOrEquals",value:function LessThanOrEquals(a){return 0>=this.Compare(a)}},{key:"GreaterThan",value:function GreaterThan(a){return 0<this.Compare(a)}},{key:"GreaterThanOrEquals",value:function GreaterThanOrEquals(a){return 0<=this.Compare(a)}},{key:"fromNumber",value:function fromNumber(c,e){var f=d.assertOptionsIsValid(e),g=a(10,f.precision);if(this.options=f,f.truncEnabled)this.value=b(c*g);else{var h=d.roundValue(0>c);this.value=b((10*(c*g)+h)/10)}}},{key:"fromString",value:function fromString(b,e){var f=b.trim().split("."),g=f.length;if(2<g)throw new Error("given value=[".concat(b,"] has more than one decimal separator"));var h=d.assertOptionsIsValid(e),i=a(10,h.precision);if(1===g||0===f[1].length){var o=parseInt(f[0],10);if(c(o))throw new Error("given invalid integer value=[".concat(b,"]"));return this.value=o*i,void(this.options=h)}var j=1,k=f[0],l=f[1],m=l.length;m!==h.precision&&(m>h.precision?l=l.substring(0,h.precision):j=a(10,h.precision-m));var n=parseInt(k+l,10);if(c(n))throw new Error("given invalid integer value=[".concat(b,"]"));this.value=n*j,this.options=h}},{key:"normalizeWith",value:function normalizeWith(a,b){return this.options.precision>a.options.precision?void b(this.value,d.adjustPrecision(a.value,a.options.precision,this.options.precision,a.options.truncEnabled)):this.options.precision<a.options.precision?void b(d.adjustPrecision(this.value,this.options.precision,a.options.precision,this.options.truncEnabled),a.value):void b(this.value,a.value)}},{key:"ToNumber",value:function ToNumber(){return this.value/a(10,this.options.precision)}}],[{key:"roundValue",value:function roundValue(a){return a?-5:5}},{key:"assertOptionsIsValid",value:function assertOptionsIsValid(a){return isNull(a)?_objectSpread({},defaultDecimalOptions):{precision:d.assertValidPrecision(a.precision),truncEnabled:d.assertValidTruncEnabled(a.truncEnabled)}}},{key:"assertValidTruncEnabled",value:function assertValidTruncEnabled(a){if(isNull(a))return defaultDecimalOptions.truncEnabled;if("boolean"!=typeof a)throw new Error("options.truncEnabled is not a boolean");return a}},{key:"assertValidPrecision",value:function assertValidPrecision(a){if(isNull(a))return defaultDecimalOptions.precision;if("number"!=typeof a)throw new Error("options.precision is not a number");if(0>a)throw new Error("invalid negative precision=[".concat(a,"]"));return b(a)}},{key:"adjustPrecision",value:function adjustPrecision(c,e,f,g){if(e===f)return b(c);if(e<f){var j=a(10,f-e);return b(c*j)}var h=a(10,e-f);if(g)return b(c/h);var i=d.roundValue(0>c);return b((c/(h/10)+i)/10)}}]),d}(),defaultDynamicOver100QuoteBase=new Currency({type:"USD",value:new Decimal("0.98",{precision:2,truncEnabled:!0})}),usd100=new Currency({type:"USD",value:new Decimal("100",{precision:2,truncEnabled:!0})}),DynamicOver100RateRule=/*#__PURE__*/function(a){function b(a){var d,e=a.quoteBase,f=a.percentage,g=a.paymentResponsible,h=a.getMoneyWrapper;return _classCallCheck(this,b),d=c.call(this),d.quoteBase=assertCurrencyIsValid(e||defaultDynamicOver100QuoteBase),d.percentage=assertDecimalIsValid(f,"DynamicOver100RateRule.percentage"),d.paymentResponsible=g,d.getMoneyWrapper=h||RateRule.defaultGetMoneyWrapper,d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"Rate",value:function Rate(a,b){var c=this.getMoneyWrapper(b);if(!RateRule.ValidateIfInputCanBeRatedWithMoneyWrapper(a,b,c))return NewRateResult();var d,e=this.paymentResponsible,f=c.originalAmount.Currency;if(c.amountUSD.Amount.LessThanOrEquals(usd100.Amount))d=this.quoteBase;else{var g=c.originalAmount.Amount.Multiply(this.percentage,{resultOptions:defaultCurrencyOptions,truncEnabled:percentageOptions.truncEnabled});d=new Currency({type:f,value:g})}if(d.Amount.Value.IsNegative)d=new Decimal,e=NoCoveragePaymentResponsible;else if(!d.HasTheSameTypeAsTheOther(c.originalAmount)){// If fixed premium and covered amount have distinct currency types, then exchange rate should be used
var h=b.ExchangeRateProvider.FindExchangeRate(d.Type,f);null===h,d=d.Exchange(h)}return NewRateResult({premiumAmount:d,paymentResponsible:e})}}]),b}(RateRule),defaultQuoteBase=new Currency({type:"USD",value:new Decimal("0.98",{precision:2,truncEnabled:!0})}),DynamicRateRule=/*#__PURE__*/function(a){function b(a){var d,e=a.quoteBase,f=a.percentage,g=a.paymentResponsible,h=a.getMoneyWrapper;return _classCallCheck(this,b),d=c.call(this),d.quoteBase=assertCurrencyIsValid(e||defaultQuoteBase),d.percentage=assertDecimalIsValid(f,"DynamicRateRule.percentage"),d.paymentResponsible=g,d.getMoneyWrapper=h||RateRule.defaultGetMoneyWrapper,d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"Rate",value:function Rate(a,b){var c=this.getMoneyWrapper(b);if(!RateRule.ValidateIfInputCanBeRatedWithMoneyWrapper(a,b,c))return NewRateResult();var d=this.paymentResponsible,e=c.originalAmount.Amount.Multiply(this.percentage,{resultOptions:defaultCurrencyOptions,truncEnabled:percentageOptions.truncEnabled});if(e.Value.IsNegative)e=new Decimal,d=NoCoveragePaymentResponsible;else{var f=this.quoteBase;if(!this.quoteBase.HasTheSameTypeAsTheOther(c.originalAmount)){// If fixed premium and covered amount have distinct currency types, then exchange rate should be used
var g=b.ExchangeRateProvider.FindExchangeRate(this.quoteBase.Type,c.originalAmount.Type);null===g,f=this.quoteBase.Exchange(g)}e.LessThan(f.Amount)&&(e=f.Amount)}return NewRateResult({premiumAmount:new Currency({value:e,type:c.originalAmount.Type}),paymentResponsible:d})}}]),b}(RateRule);function assertExchangeRateIsValid(a){if(isNull(a))throw new Error("given exchange rate is null");if(isNull(a.to))throw new Error("given exchange rate does not have the \"to\" property");if(isNull(a.from))throw new Error("given exchange rate does not have the \"from\" property");if(assertDecimalIsValid(a.rate,"assertExchangeRateIsValid.rate"),a.to!==defaultCurrencyType&&a.from!==defaultCurrencyType)throw new Error("exchange rate must have the \"from\" or \"to\" property with the currency type=[".concat(defaultCurrencyType,"]"));return a}var ExchangeRate=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{from:defaultCurrencyType,to:defaultCurrencyType,rate:new Decimal(1,defaultExchangeRateOptions)},c=b.from,d=void 0===c?defaultCurrencyType:c,e=b.to,f=void 0===e?defaultCurrencyType:e,g=b.rate,h=void 0===g?new Decimal(1,defaultExchangeRateOptions):g;_classCallCheck(this,a);var i=h;h instanceof Decimal||(i=new Decimal(h,defaultExchangeRateOptions)),this.to=f,this.from=d,this.rate=i}return _createClass(a,[{key:"ToCurrencyType",get:function get(){return this.to}},{key:"FromCurrencyType",get:function get(){return this.from}},{key:"Rate",get:function get(){return this.rate}}]),a}(),one=new Decimal(1,{precision:0}),LocalExchangeRateProvider=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;_classCallCheck(this,a),this.exchangeRate=b}return _createClass(a,[{key:"FindExchangeRate",value:function FindExchangeRate(a,b){if(this.exchangeRate.ToCurrencyType===b){if(this.exchangeRate.FromCurrencyType===a)return this.exchangeRate;}else if(this.exchangeRate.ToCurrencyType===a&&this.exchangeRate.FromCurrencyType===b)return new ExchangeRate({from:a,to:b,rate:one.Divide(this.exchangeRate.Rate)});throw new Error("no exchange rate found from=".concat(a," to=").concat(b))}}]),a}(),FixedAmountRateRule=/*#__PURE__*/function(a){function b(a){var d,e=a.premiumAmount,f=a.paymentResponsible,g=a.getMoneyWrapper;return _classCallCheck(this,b),d=c.call(this),d.premiumAmount=e,d.paymentResponsible=f,d.getMoneyWrapper=g||RateRule.defaultGetMoneyWrapper,d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"Rate",value:function Rate(a,b){var c=this.getMoneyWrapper(b);if(!RateRule.ValidateIfInputCanBeRatedWithMoneyWrapper(a,b,c))return NewRateResult();if(this.premiumAmount.HasTheSameTypeAsTheOther(b.CartInfo.CoveredAmount))return NewRateResult({premiumAmount:this.premiumAmount,paymentResponsible:this.paymentResponsible});// If fixed premium and covered amount have distinct currency types, then exchange rate should be used
var d=b.ExchangeRateProvider.FindExchangeRate(this.premiumAmount.Type,b.CartInfo.CoveredAmount.Type);var e=this.premiumAmount.Exchange(d);return NewRateResult({premiumAmount:e,paymentResponsible:this.paymentResponsible})}}]),b}(RateRule),Input=/*#__PURE__*/function(){function a(b){var c=b.cartInfo,d=b.exchangeRateProvider,e=b.coverageAgreement,f=b.merchantParams;_classCallCheck(this,a),this.cartInfo=assertNotNull(c),this.exchangeRateProvider=assertNotNull(d),this.coverageAgreement=assertNotNull(e),this.merchant_params=_objectSpread({},f)}return _createClass(a,[{key:"CartInfo",get:function get(){return this.cartInfo}},{key:"ExchangeRateProvider",get:function get(){return this.exchangeRateProvider}},{key:"CoverageAgreement",get:function get(){return this.coverageAgreement}}]),a}();function newMoneyWrapper(a,b,c){if(!a)throw new Error("newMoneyWrapper: input given is null");if(c&&a[c])return a[c];// cached value
var d=new Currency({type:"USD",amount:0}),e={originalAmount:d,amountUSD:d};if(b)if(e.originalAmount=assertCurrencyIsValid(b),"USD"===e.originalAmount.Currency)e.amountUSD=e.originalAmount;else{if(!a.ExchangeRateProvider)throw new Error("newMoneyWrapper: input.ExchangeRateProvider given is null");if(!a.ExchangeRateProvider.FindExchangeRate)throw new Error("newMoneyWrapper: input.ExchangeRateProvider.FindExchangeRate given is null");var f=e.originalAmount.Currency,g=a.ExchangeRateProvider.FindExchangeRate(f,defaultCurrencyType);if(!g)throw new Error("newMoneyWrapper: exchange rate not found for ".concat(f," to ").concat(defaultCurrencyType));// Validate exchange rate structure
if(!g.FromCurrencyType||!g.ToCurrencyType||!g.Rate)throw new Error("newMoneyWrapper: invalid exchange rate structure");e.amountUSD=e.originalAmount.Exchange(g)}return c&&(a[c]=e),e}var NoCoverageRateRule={Rate:function Rate(){return NoCoverageResult}},NoCoveragePaymentResponsible={type:"no_coverage"};function MerchantPaymentResponsible(a){return a?{type:"merchant",additional_info:a}:{type:"merchant"}}// ShopifyOptInBulkMigrationEnabled allows Coverage Service disable the toggle checked state (opt-in)
var ShopifyOptInBulkMigrationEnabled=!1;// EnableShopifyOptInBulkMigration is added to the main quote function if the Shopify opt-in bulk migration is enabled
// in the server side and the merchant is in the whitelist.
function EnableShopifyOptInBulkMigration(){ShopifyOptInBulkMigrationEnabled=!0}function CustomerPaymentResponsible(){var a=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],b=1<arguments.length?arguments[1]:void 0,c="unchecked";return a&&!ShopifyOptInBulkMigrationEnabled&&(c="checked"),b?{type:"customer",toggle_state:c,additional_info:b}:{type:"customer",toggle_state:c}}var PercentageRateRule=/*#__PURE__*/function(a){function b(a){var d,e=a.percentage,f=a.paymentResponsible,g=a.getMoneyWrapper;return _classCallCheck(this,b),d=c.call(this),d.percentage=assertDecimalIsValid(e,"PercentageRateRule.percentage"),d.paymentResponsible=f||NoCoveragePaymentResponsible,d.getMoneyWrapper=g||RateRule.defaultGetMoneyWrapper,d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"Rate",value:function Rate(a,b){var c=this.getMoneyWrapper(b);if(!RateRule.ValidateIfInputCanBeRatedWithMoneyWrapper(a,b,c))return NewRateResult();if(!this.percentage.IsPositive||!c.originalAmount.Amount.IsPositive)return NewRateResult();var d=this.paymentResponsible,e=c.originalAmount.Amount.Multiply(this.percentage,{resultOptions:defaultCurrencyOptions,truncEnabled:percentageOptions.truncEnabled});return NewRateResult({premiumAmount:new Currency({value:e,type:c.originalAmount.Type}),paymentResponsible:d})}}]),b}(RateRule);/*
const coveredExample1 = new Currency({currency: 'USD', amount: 23.45});
const coveredExample2 = new Currency({amount: 23.45});
const exchangeRateExample1 = new ExchangeRate({from: 'CAD', rate: 5.67});
*/function quote06e5fc221(a,b,c,d){/*
   Each product rate rule is injected in the backendRateRule object using as key the TypeID, so
   backendRateRule.protect is where the rate rule for the protect product it is. If this property is undefined, then
   the merchant does not have Protect configured.
   */if(!backendRateRule.protect)// protect product not configured for the merchant
return NoCoverageResult;assertCurrencyIsValid(a);var e=assertExchangeRateIsValid(b||backendExchangeRate);return backendRateRule.protect.Rate({},new Input({cartInfo:new CartInfo({coveredAmount:a,coveredWithDiscounts:d}),coverageAgreement:assertCoverageAgreementIsValid(backendCoverageAgreement.protect),exchangeRateProvider:new LocalExchangeRateProvider(e),merchantParams:c}))}var quote=quote06e5fc221;/* NewRateResult must return what expected by front-end */function NewRateResult(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{premiumAmount:new Currency,paymentResponsible:NoCoveragePaymentResponsible},b=a.premiumAmount,c=void 0===b?new Currency:b,d=a.paymentResponsible,e=void 0===d?NoCoveragePaymentResponsible:d,f=a.notes,g={premium:{currency:c.Type,amount:c.Amount.ToNumber()},payment_responsible:e};return f&&(g.notes=f),g}var NoCoverageResult=NewRateResult(),zero=new Currency,noCoverageV3={fee:{currency:zero.Type,amount:0},payment_responsible:NoCoveragePaymentResponsible};/*
const coveredExample1 = new Currency({currency: 'USD', amount: 23.45});
const coveredExample2 = new Currency({amount: 23.45});
const exchangeRateExample1 = new ExchangeRate({from: 'CAD', rate: 5.67});
*/function convertToV3Result(a){if(!a)return noCoverageV3;var b=a.premium?a.premium:{currency:"USD",amount:0},c=a.payment_responsible?a.payment_responsible:NoCoveragePaymentResponsible,d={fee:b,payment_responsible:c},e=a.notes?a.notes:void 0;return e&&(d.notes=e),d}/*
 addFee expects as input the following data types:
 - current: undefined | {currency: string, amount: number}
 - fee: undefined | {currency: string, amount: number}
 */function addFee(a,b){var c=a;return b&&(c?b.amount&&(c.amount+=b.amount,c.currency=b.currency):c=b),c}function v3Quote06e5fc221(a,b,c,d){assertCurrencyIsValid(a);var e=assertExchangeRateIsValid(b||backendExchangeRate),f={products:{},total:{merchant:{amount:0,currency:"USD"},customer:{amount:0,currency:"USD"}}};return backendProducts.forEach(function(b){var g=backendRateRule[b];if(!g)f.products[b]=noCoverageV3;else{var j=backendCoverageAgreement[b];if(isNull(j))return void(f.products[b]=noCoverageV3);// each product rate rule needs an input with its agreement
var h=new Input({cartInfo:new CartInfo({coveredAmount:a,coveredWithDiscounts:d}),coverageAgreement:assertCoverageAgreementIsValid(j),exchangeRateProvider:new LocalExchangeRateProvider(e),merchantParams:c}),i=convertToV3Result(g.Rate({},h));"merchant"===i.payment_responsible.type?f.total.merchant=addFee(f.total.merchant,i.fee):"customer"===i.payment_responsible.type&&(f.total.customer=addFee(f.total.customer,i.fee)),f.products[b]=i}}),f}var quoteV3=v3Quote06e5fc221,routeQuoteV3=v3Quote06e5fc221;// eslint-disable-next-line no-unused-vars
const backendCoverageAgreement = Object.freeze({
  protect: { TypeID: 'protect', UpperLimit: new Decimal(5000.00, {precision: 2, truncEnabled: false}), LowerLimit: new Decimal(0.00, {precision: 2, truncEnabled: false}), State: 'disabled' },
});
var backendExchangeRate = new ExchangeRate({from: 'AUD', to: 'USD', rate: '0.668400'});
const backendRateRule = Object.freeze({
  protect: new ConditionalRateRule({condition: new AndCondition([new Condition((ctx, input) => { return input.CartInfo.CoveredAmountInUSD(ctx, input.ExchangeRateProvider).Amount.GreaterThan(new Decimal(0.00, {precision: 2, truncEnabled: true})) }),new Condition((ctx, input) => { return input.CartInfo.CoveredAmountInUSD(ctx, input.ExchangeRateProvider).Amount.LessThanOrEquals(new Decimal(100.00, {precision: 2, truncEnabled: true})) })]), rateRule: new FixedAmountRateRule({premiumAmount: new Currency({type: 'USD', value: new Decimal(1.95, {precision: 2, truncEnabled: false})}), getMoneyWrapper: (input) => newMoneyWrapper(input, input?.CartInfo?.CoveredAmount, '/cart/covered'), paymentResponsible: CustomerPaymentResponsible(true)}), fallbackRateRule: new ConditionalRateRule({condition: new AndCondition([new Condition((ctx, input) => { return input.CartInfo.CoveredAmountInUSD(ctx, input.ExchangeRateProvider).Amount.GreaterThan(new Decimal(100.00, {precision: 2, truncEnabled: true})) }),new Condition((ctx, input) => { return input.CartInfo.CoveredAmountInUSD(ctx, input.ExchangeRateProvider).Amount.LessThanOrEquals(new Decimal(5000.00, {precision: 2, truncEnabled: true})) })]), rateRule: new PercentageRateRule({percentage: new Decimal(0.0300, {precision: 4, truncEnabled: false}), getMoneyWrapper: (input) => newMoneyWrapper(input, input?.CartInfo?.CoveredAmount, '/cart/covered'), paymentResponsible: CustomerPaymentResponsible(true)}), fallbackRateRule: new PercentageRateRule({percentage: new Decimal(0.0300, {precision: 4, truncEnabled: false}), getMoneyWrapper: (input) => newMoneyWrapper(input, input?.CartInfo?.CoveredAmount, '/cart/covered'), paymentResponsible: CustomerPaymentResponsible(true)}), name: '100-5000'}), name: '0-100'}),
});
const backendProducts = Object.freeze(['protect']);
window.__Route = { quote, Currency, backendExchangeRate, quoteV3, Decimal, ExchangeRate } })();
