using Baya.Domain.Entities.Holidays;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Baya.Infrastructure.Persistence.Configuration.HolidaysConfig;

internal sealed class IranianHolidayConfig : IEntityTypeConfiguration<IranianHoliday>
{
    public void Configure(EntityTypeBuilder<IranianHoliday> builder)
    {
        builder.ToTable("IranianHolidays", "ops");

        builder.Property(h => h.NameFa).HasMaxLength(200).IsRequired();
        builder.Property(h => h.Type).HasMaxLength(20).IsRequired();

        builder.HasIndex(h => h.HolidayDate).IsUnique();

        builder.HasData(SeedData());
    }

    // A representative sample so IsBankClosed/NextBusinessDay are testable. The full, maintained,
    // partly-lunar-Hijri feed is deferred behind IHolidayCalendar's "make it real" path.
    private static object[] SeedData()
    {
        var ts = SeedConstants.Timestamp;

        (long Id, DateOnly Date, string NameFa, string Type, bool BankClosed)[] rows =
        [
            (1, new DateOnly(2026, 2, 11), "پیروزی انقلاب اسلامی", HolidayType.National, true),
            (2, new DateOnly(2026, 3, 21), "نوروز", HolidayType.National, true),
            (3, new DateOnly(2026, 3, 22), "نوروز", HolidayType.National, true),
            (4, new DateOnly(2026, 3, 23), "نوروز", HolidayType.National, true),
            (5, new DateOnly(2026, 3, 24), "نوروز", HolidayType.National, true),
            (6, new DateOnly(2026, 4, 1), "روز طبیعت (سیزده‌به‌در)", HolidayType.Official, true),
            (7, new DateOnly(2026, 6, 26), "عید سعید قربان", HolidayType.Religious, true),
        ];

        return rows
            .Select(r => (object)new
            {
                r.Id,
                HolidayDate = r.Date,
                r.NameFa,
                r.Type,
                IsBankClosed = r.BankClosed,
                CreatedAt = ts
            })
            .ToArray();
    }
}
