namespace Meezi.API.Services;

public static class IranCalendar
{
    private static readonly TimeZoneInfo IranTz = TimeZoneInfo.FindSystemTimeZoneById(
        OperatingSystem.IsWindows() ? "Iran Standard Time" : "Asia/Tehran");

    public static DateOnly TodayInIran =>
        DateOnly.FromDateTime(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, IranTz));

    public static DateTime NowInIran =>
        TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, IranTz);

    public static TimeZoneInfo TimeZone => IranTz;

    public static (DateTime UtcStart, DateTime UtcEndExclusive) GetUtcRangeForIranDay(DateOnly date)
    {
        var localStart = date.ToDateTime(TimeOnly.MinValue);
        var localEnd = date.AddDays(1).ToDateTime(TimeOnly.MinValue);
        var utcStart = TimeZoneInfo.ConvertTimeToUtc(
            DateTime.SpecifyKind(localStart, DateTimeKind.Unspecified), IranTz);
        var utcEnd = TimeZoneInfo.ConvertTimeToUtc(
            DateTime.SpecifyKind(localEnd, DateTimeKind.Unspecified), IranTz);
        return (utcStart, utcEnd);
    }
}
