// EN: Entity type configuration for Resource.
// VI: Cấu hình entity type cho Resource.

using BookingService.Domain.AggregatesModel.ResourceAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace BookingService.Infrastructure.EntityConfigurations;

/// <summary>
/// EN: Entity type configuration for Resource aggregate.
/// VI: Cấu hình entity type cho aggregate Resource.
/// </summary>
public class ResourceEntityTypeConfiguration : IEntityTypeConfiguration<Resource>
{
    public void Configure(EntityTypeBuilder<Resource> builder)
    {
        builder.ToTable("resources");
        
        builder.HasKey(r => r.Id);
        builder.Property(r => r.Id)
            .HasColumnName("id")
            .ValueGeneratedNever();

        builder.Property(r => r.ShopId)
            .HasField("_shopId")
            .HasColumnName("shop_id")
            .IsRequired();

        builder.Property(r => r.Name)
            .HasField("_name")
            .HasColumnName("name")
            .HasMaxLength(200)
            .IsRequired();

        builder.Property(r => r.ResourceType)
            .HasField("_resourceType")
            .HasColumnName("resource_type")
            .HasMaxLength(50)
            .IsRequired();

        builder.Property(r => r.Capacity)
            .HasField("_capacity")
            .HasColumnName("capacity")
            .IsRequired();

        builder.Property(r => r.IsActive)
            .HasField("_isActive")
            .HasColumnName("is_active")
            .IsRequired();

        builder.Property(r => r.CreatedAt)
            .HasField("_createdAt")
            .HasColumnName("created_at")
            .IsRequired();

        // EN: Indexes / VI: Indexes
        builder.HasIndex(r => r.ShopId)
            .HasDatabaseName("ix_resources_shop_id");
    }
}
