using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using FnbEngine.Domain.AggregatesModel.ReservationAggregate;

namespace FnbEngine.Infrastructure.EntityConfigurations;

public class ReservationEntityTypeConfiguration : IEntityTypeConfiguration<Reservation>
{
    public void Configure(EntityTypeBuilder<Reservation> builder)
    {
        builder.ToTable("reservations");

        builder.HasKey(r => r.Id);
        builder.Property(r => r.Id).HasColumnName("id").IsRequired();

        builder.Property(r => r.ShopId).HasField("_shopId").HasColumnName("shop_id").IsRequired();
        builder.Property(r => r.TableId).HasField("_tableId").HasColumnName("table_id");
        builder.Property(r => r.GuestName).HasField("_guestName").HasColumnName("guest_name").HasMaxLength(200).IsRequired();
        builder.Property(r => r.Phone).HasField("_phone").HasColumnName("phone").HasMaxLength(20);
        builder.Property(r => r.PartySize).HasField("_partySize").HasColumnName("party_size").IsRequired();
        builder.Property(r => r.ReservationTime).HasField("_reservationTime").HasColumnName("reservation_time").IsRequired();
        builder.Property(r => r.Status).HasField("_status").HasColumnName("status").HasMaxLength(20).IsRequired();
        builder.Property(r => r.Note).HasField("_note").HasColumnName("note").HasMaxLength(500);
        builder.Property(r => r.CreatedAt).HasField("_createdAt").HasColumnName("created_at").IsRequired();

        builder.HasIndex(r => r.ShopId).HasDatabaseName("ix_reservations_shop_id");
        builder.HasIndex(r => new { r.ShopId, r.ReservationTime }).HasDatabaseName("ix_reservations_shop_time");
    }
}
