// EN: Session entity configuration.
// VI: Cấu hình entity Session.

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

namespace FnbEngine.Infrastructure.EntityConfigurations;

/// <summary>
/// EN: Entity configuration for Session.
/// VI: Cấu hình entity cho Session.
/// </summary>
public class SessionEntityTypeConfiguration : IEntityTypeConfiguration<Session>
{
    public void Configure(EntityTypeBuilder<Session> builder)
    {
        builder.ToTable("sessions");

        builder.HasKey(s => s.Id);

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

        builder.Property(s => s.TableId)
            .HasColumnName("table_id")
            .IsRequired();

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

        builder.Property(s => s.GuestCount)
            .HasColumnName("guest_count")
            .IsRequired();

        builder.Property(s => s.StartedAt)
            .HasColumnName("started_at")
            .IsRequired();

        builder.Property(s => s.ClosedAt)
            .HasColumnName("closed_at");

        builder.Property(s => s.Status)
            .HasColumnName("status")
            .HasMaxLength(50)
            .IsRequired();

        // EN: Index for querying active sessions by table
        // VI: Index để query phiên đang hoạt động theo bàn
        builder.HasIndex(s => new { s.TableId, s.Status })
            .HasDatabaseName("ix_sessions_table_status");

        // EN: Index for querying by shop
        // VI: Index để query theo shop
        builder.HasIndex(s => s.ShopId)
            .HasDatabaseName("ix_sessions_shop");
    }
}
