using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using AdsBillingService.Infrastructure.Idempotency;

namespace AdsBillingService.Infrastructure.EntityConfigurations;

/// <summary>
/// EN: Entity configuration for ClientRequest (idempotency).
/// VI: Cấu hình entity cho ClientRequest (idempotency).
/// </summary>
public class ClientRequestEntityTypeConfiguration : IEntityTypeConfiguration<ClientRequest>
{
    public void Configure(EntityTypeBuilder<ClientRequest> builder)
    {
        // EN: Table name / VI: Tên bảng
        builder.ToTable("client_requests");

        // EN: Primary key / VI: Khóa chính
        builder.HasKey(cr => cr.Id);
        builder.Property(cr => cr.Id)
            .HasColumnName("id")
            .IsRequired();

        // EN: Request ID / VI: ID yêu cầu
        builder.Property(cr => cr.Name)
            .HasColumnName("name")
            .HasMaxLength(200)
            .IsRequired();

        builder.HasIndex(cr => cr.Name)
            .IsUnique()
            .HasDatabaseName("ix_client_requests_name");

        // EN: Timestamp / VI: Thời gian
        builder.Property(cr => cr.Time)
            .HasColumnName("time")
            .IsRequired();
    }
}
