ex-int-04-shipping-cost/ShippingCosts/Implementations/CountryDistanceProvider.cs
2025-05-09 10:19:28 +02:00

41 lines
1.8 KiB
C#

using ShippingCosts.Contracts;
namespace ShippingCosts.Implementations;
/// <summary>
/// Default implementation of <see cref="ICountryDistanceProvider" /> providing distance information
/// for several countries
/// </summary>
/// <inheritdoc cref="ICountryDistanceProvider" />
public sealed class CountryDistanceProvider : ICountryDistanceProvider
{
private static readonly Dictionary<string, CountryDistanceInformation> distanceDatabase = new()
{
["Brazil"] = new CountryDistanceInformation(9820, false, false),
["China"] = new CountryDistanceInformation(7466, false, false),
["Egypt"] = new CountryDistanceInformation(2906, false, false),
["France"] = new CountryDistanceInformation(1036, false, true),
["Germany"] = new CountryDistanceInformation(524, true, true),
["India"] = new CountryDistanceInformation(6186, false, false),
["Israel"] = new CountryDistanceInformation(2739, false, false),
["Italy"] = new CountryDistanceInformation(763, true, true),
["Japan"] = new CountryDistanceInformation(9278, false, false),
["Malaysia"] = new CountryDistanceInformation(9766, false, false),
["Namibia"] = new CountryDistanceInformation(8239, false, false),
["United Kingdom"] = new CountryDistanceInformation(1228, false, false),
["United States"] = new CountryDistanceInformation(7832, false, false),
["Switzerland"] = new CountryDistanceInformation(692, true, false)
};
public CountryDistanceInformation? GetDistanceTo(string countryName)
{
bool success = distanceDatabase.TryGetValue(countryName, out var distance);
return success ? distance : null;
}
public bool IsPossibleCountry(string countryName)
{
var country = GetDistanceTo(countryName);
return country != null;
}
}