namespace Fengling.Platform.Infrastructure.Configurations;

using Fengling.Platform.Domain.AggregatesModel.TenantAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

public class TenantConfiguration : IEntityTypeConfiguration<Tenant>
{
    public void Configure(EntityTypeBuilder<Tenant> builder)
    {
        builder.ToTable("Platform_Tenants");

        builder.HasKey(t => t.Id);
        builder.Property(t => t.Id).ValueGeneratedOnAdd();

        builder.Property(t => t.TenantCode)
            .IsRequired()
            .HasMaxLength(50);

        builder.Property(t => t.Name)
            .IsRequired()
            .HasMaxLength(100);

        builder.Property(t => t.ContactName)
            .IsRequired()
            .HasMaxLength(50);

        builder.Property(t => t.ContactEmail)
            .IsRequired()
            .HasMaxLength(100);

        builder.Property(t => t.ContactPhone)
            .HasMaxLength(20);

        builder.Property(t => t.Description)
            .HasMaxLength(500);

        builder.Property(t => t.Status)
            .HasConversion<int>();

        builder.HasIndex(t => t.TenantCode).IsUnique();
        builder.HasIndex(t => t.Status);
    }
}
