namespace SIGCM2.Domain.Pricing;

/// <summary>
/// Domain-layer extension for TimeProvider: returns Argentina civil date.
/// Mirrors SIGCM2.Application.Common.TimeProviderArgentinaExtensions
/// but lives in Domain to avoid a Domain → Application dependency.
/// Domain layer is pure — no Application references allowed.
/// </summary>
internal static class DomainTimeProviderExtensions
{
    private const string ArgentinaTimeZoneId        = "America/Argentina/Buenos_Aires";
    private const string ArgentinaTimeZoneIdWindows = "Argentina Standard Time";

    private static readonly TimeZoneInfo ArgentinaTz = LoadArgentinaTz();

    internal static DateOnly GetArgentinaToday(this TimeProvider timeProvider)
    {
        var utcNow       = timeProvider.GetUtcNow();
        var argentinaNow = TimeZoneInfo.ConvertTime(utcNow, ArgentinaTz);
        return DateOnly.FromDateTime(argentinaNow.DateTime);
    }

    private static TimeZoneInfo LoadArgentinaTz()
    {
        try
        {
            return TimeZoneInfo.FindSystemTimeZoneById(ArgentinaTimeZoneId);
        }
        catch (TimeZoneNotFoundException)
        {
            return TimeZoneInfo.FindSystemTimeZoneById(ArgentinaTimeZoneIdWindows);
        }
    }
}
