dotnet-geo-management/Svrnty.GeoManagement.Abstractions/Models/Address.cs
Mathias Beaulieu-Duncan 57c9aa6e00
Some checks failed
Publish NuGet Packages / build-and-publish (push) Failing after 41s
added nuget publish workflow
2025-10-06 15:12:38 -04:00

61 lines
1.4 KiB
C#

using Svrnty.GeoManagement.Abstractions.Abstractions;
namespace Svrnty.GeoManagement.Abstractions.Models;
public record GeoPoint(double Latitude, double Longitude);
public record Address(
string Line1,
string? Line2,
string City,
string Subdivision,
string PostalCode,
string Country,
GeoPoint? Location,
string? Note,
bool IsNormalized = false
) : IAddress
{
public string GetFormattedAddress(
FormattedAddressType formatType = FormattedAddressType.Full
)
{
return formatType switch
{
FormattedAddressType.Full => FormatFullOneLine(),
FormattedAddressType.Compact => FormatCompactOneLine(),
FormattedAddressType.MultiLine => FormatMultiLine(),
_ => FormatFullOneLine()
};
}
private string FormatFullOneLine()
{
if (string.IsNullOrWhiteSpace(Line2))
{
return $"{Line1}, {City}, {Subdivision} {PostalCode}, {Country}";
}
return $"{Line2}, {Line1}, {City}, {Subdivision} {PostalCode}, {Country}";
}
private string FormatCompactOneLine()
{
if (string.IsNullOrWhiteSpace(Line2))
{
return $"{Line1}, {City}, {Subdivision}";
}
return $"{Line2}, {Line1}, {City}, {Subdivision}";
}
private string FormatMultiLine()
{
if (string.IsNullOrWhiteSpace(Line2))
{
return $"{Line1}\n{City}, {Subdivision} {PostalCode}\n{Country}";
}
return $"{Line2}, {Line1}\n{City}, {Subdivision} {PostalCode}\n{Country}";
}
}