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

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

namespace BookingService.Infrastructure.EntityConfigurations;

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

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

        builder.Property<Guid?>("_customerId")
            .HasColumnName("customer_id");

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

        builder.Property<Guid?>("_resourceId")
            .HasColumnName("resource_id");

        builder.Property<Guid>("_serviceId")
            .HasColumnName("service_id")
            .IsRequired();

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

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

        builder.Property<string>("_status")
            .HasColumnName("status")
            .HasMaxLength(50)
            .IsRequired();

        builder.Property<DateTime>("_createdAt")
            .HasColumnName("created_at")
            .IsRequired();

        // EN: Indexes / VI: Indexes
        builder.HasIndex("_shopId")
            .HasDatabaseName("ix_appointments_shop_id");

        builder.HasIndex("_customerId")
            .HasDatabaseName("ix_appointments_customer_id");

        builder.HasIndex("_staffId")
            .HasDatabaseName("ix_appointments_staff_id");

        builder.HasIndex("_startTime")
            .HasDatabaseName("ix_appointments_start_time");

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