// EN: Entity type configuration for StaffSchedule.
// VI: Cấu hình entity type cho StaffSchedule.

using BookingService.Domain.AggregatesModel.StaffAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace BookingService.Infrastructure.EntityConfigurations;

/// <summary>
/// EN: Entity type configuration for StaffSchedule entity.
/// VI: Cấu hình entity type cho entity StaffSchedule.
/// </summary>
public class StaffScheduleEntityTypeConfiguration : IEntityTypeConfiguration<StaffSchedule>
{
    public void Configure(EntityTypeBuilder<StaffSchedule> builder)
    {
        builder.ToTable("staff_schedules");
        
        builder.HasKey(s => s.Id);
        builder.Property(s => s.Id)
            .HasColumnName("id")
            .ValueGeneratedNever();

        builder.Property<Guid>("_staffId")
            .HasColumnName("staff_id")
            .IsRequired();

        builder.Property<Guid>("_shopId")
            .HasColumnName("shop_id")
            .IsRequired();

        builder.Property<int>("_dayOfWeek")
            .HasColumnName("day_of_week")
            .IsRequired();

        builder.Property<TimeOnly>("_startTime")
            .HasColumnName("start_time")
            .IsRequired();

        builder.Property<TimeOnly>("_endTime")
            .HasColumnName("end_time")
            .IsRequired();

        // EN: Indexes / VI: Indexes
        builder.HasIndex("_staffId", "_dayOfWeek")
            .HasDatabaseName("ix_staff_schedules_staff_day");

        builder.HasIndex("_shopId")
            .HasDatabaseName("ix_staff_schedules_shop_id");

        // EN: Ignore public properties (mapped via backing fields)
        // VI: Bỏ qua các properties công khai (đã map qua backing fields)
        builder.Ignore(s => s.StaffId);
        builder.Ignore(s => s.ShopId);
        builder.Ignore(s => s.DayOfWeek);
        builder.Ignore(s => s.StartTime);
        builder.Ignore(s => s.EndTime);
    }
}
