// 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(s => s.StaffId)
            .HasField("_staffId")
            .HasColumnName("staff_id")
            .IsRequired();

        builder.Property(s => s.ShopId)
            .HasField("_shopId")
            .HasColumnName("shop_id")
            .IsRequired();

        builder.Property(s => s.DayOfWeek)
            .HasField("_dayOfWeek")
            .HasColumnName("day_of_week")
            .IsRequired();

        builder.Property(s => s.StartTime)
            .HasField("_startTime")
            .HasColumnName("start_time")
            .IsRequired();

        builder.Property(s => s.EndTime)
            .HasField("_endTime")
            .HasColumnName("end_time")
            .IsRequired();

        // EN: Indexes / VI: Indexes
        builder.HasIndex(s => new { s.StaffId, s.DayOfWeek })
            .HasDatabaseName("ix_staff_schedules_staff_day");

        builder.HasIndex(s => s.ShopId)
            .HasDatabaseName("ix_staff_schedules_shop_id");
    }
}
