35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using ShippingCosts.Contracts;
|
|
|
|
namespace ShippingCosts.Implementations;
|
|
|
|
/// <summary>
|
|
/// A shipping cost calculator for the LuxuryShipping carrier
|
|
/// </summary>
|
|
/// <inheritdoc cref="ShippingCostCalculatorBase" />
|
|
public sealed class LuxuryShippingCostCalculator(ICountryDistanceProvider countryDistanceProvider)
|
|
: ShippingCostCalculatorBase(countryDistanceProvider)
|
|
{
|
|
public override string CarrierName => "LuxuryShipping";
|
|
|
|
public override decimal? CalculateShippingCosts(string targetCountry, IMeasuredBox box)
|
|
{
|
|
const decimal MaxPrice = 4444M;
|
|
|
|
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);
|
|
|
|
static double ToCentimeters(double millimeters) => millimeters / 10D;
|
|
}
|
|
}
|