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

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

namespace FnbEngine.Infrastructure.EntityConfigurations;

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

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

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

        builder.Property(kt => kt.SessionId)
            .HasColumnName("session_id")
            .IsRequired();

        builder.Property(kt => kt.OrderItemId)
            .HasColumnName("order_item_id")
            .IsRequired();

        builder.Property(kt => kt.ItemName)
            .HasColumnName("item_name")
            .HasMaxLength(200)
            .IsRequired();

        builder.Property(kt => kt.Station)
            .HasColumnName("station")
            .HasMaxLength(100);

        builder.Property(kt => kt.Priority)
            .HasColumnName("priority")
            .IsRequired();

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

        builder.Property(kt => kt.CreatedAt)
            .HasColumnName("created_at")
            .IsRequired();

        builder.Property(kt => kt.CompletedAt)
            .HasColumnName("completed_at");

        // EN: Index for querying by session
        // VI: Index để query theo phiên
        builder.HasIndex(kt => kt.SessionId)
            .HasDatabaseName("ix_kitchen_tickets_session");

        // EN: Index for querying pending tickets by station
        // VI: Index để query phiếu chờ theo trạm
        builder.HasIndex(kt => new { kt.Station, kt.Status, kt.Priority })
            .HasDatabaseName("ix_kitchen_tickets_station_status_priority");
    }
}
