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

namespace FnbEngine.Infrastructure.EntityConfigurations;

public class TableEntityTypeConfiguration : IEntityTypeConfiguration<Table>
{
    public void Configure(EntityTypeBuilder<Table> builder)
    {
        builder.ToTable("tables");
        
        builder.HasKey(t => t.Id);
        
        builder.Property(t => t.Id)
            .HasColumnName("id")
            .IsRequired();

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

        builder.Property<string>("_tableNumber")
            .HasColumnName("table_number")
            .HasMaxLength(20)
            .IsRequired();

        builder.Property<int>("_capacity")
            .HasColumnName("capacity")
            .IsRequired();

        builder.Property<string?>("_zone")
            .HasColumnName("zone")
            .HasMaxLength(100);

        builder.Property(t => t.StatusId)
            .HasColumnName("status_id")
            .IsRequired();

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

        builder.Property<DateTime?>("_updatedAt")
            .HasColumnName("updated_at");

        // EN: Indexes / VI: Các index
        builder.HasIndex("_shopId")
            .HasDatabaseName("ix_tables_shop_id");

        builder.HasIndex("_shopId", "_tableNumber")
            .HasDatabaseName("ix_tables_shop_table_number")
            .IsUnique();

        // EN: Ignore navigation properties / VI: Bỏ qua các navigation properties
        builder.Ignore(t => t.ShopId);
        builder.Ignore(t => t.TableNumber);
        builder.Ignore(t => t.Capacity);
        builder.Ignore(t => t.Zone);
        builder.Ignore(t => t.Status);
        builder.Ignore(t => t.CreatedAt);
        builder.Ignore(t => t.UpdatedAt);
    }
}
