From 295192dcfaead676fc981a37ec4c5b2920052885 Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Fri, 9 May 2025 23:43:03 +0200 Subject: [PATCH] Implemented LuxuryShippingCostCalculator.cs --- .../LuxuryShippingCostCalculator.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ShippingCosts/Implementations/LuxuryShippingCostCalculator.cs b/ShippingCosts/Implementations/LuxuryShippingCostCalculator.cs index 0b769fd..600d226 100644 --- a/ShippingCosts/Implementations/LuxuryShippingCostCalculator.cs +++ b/ShippingCosts/Implementations/LuxuryShippingCostCalculator.cs @@ -9,16 +9,27 @@ namespace ShippingCosts.Implementations; public sealed class LuxuryShippingCostCalculator(ICountryDistanceProvider countryDistanceProvider) : ShippingCostCalculatorBase(countryDistanceProvider) { - public override string CarrierName => string.Empty; // TODO + public override string CarrierName => "LuxuryShipping"; public override decimal? CalculateShippingCosts(string targetCountry, IMeasuredBox box) { - //const decimal MaxPrice = 4444M; + const decimal MaxPrice = 4444M; - // TODO + var countryInfo = CountryDistanceProvider.GetDistanceTo(targetCountry); + if (countryInfo == null) + { + return null; + } + + double width = ToCentimeters(box.Width); + double height = ToCentimeters(box.Height); + double depth = ToCentimeters(box.Depth); + + double boxSizeCost = Math.Pow(width * height * depth, 2); + decimal totalCost = (decimal)(countryInfo.Value.ApproxDistance * boxSizeCost); + + return Math.Min(totalCost, MaxPrice); - return null; - - //static double ToCentimeters(double millimeters) => millimeters / 10D; + static double ToCentimeters(double millimeters) => millimeters / 10D; } }