using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SolutionErp.Domain.Forms;

namespace SolutionErp.Infrastructure.Persistence.Configurations;

public class ContractTemplateConfiguration : IEntityTypeConfiguration<ContractTemplate>
{
    public void Configure(EntityTypeBuilder<ContractTemplate> b)
    {
        b.ToTable("ContractTemplates");
        b.HasKey(x => x.Id);

        b.Property(x => x.FormCode).HasMaxLength(50).IsRequired();
        b.Property(x => x.Name).HasMaxLength(200).IsRequired();
        b.Property(x => x.ContractType).HasConversion<int?>();
        b.Property(x => x.FileName).HasMaxLength(255).IsRequired();
        b.Property(x => x.StoragePath).HasMaxLength(500).IsRequired();
        b.Property(x => x.Format).HasMaxLength(10).IsRequired();
        b.Property(x => x.FieldSpec).HasColumnType("nvarchar(max)");
        b.Property(x => x.Description).HasMaxLength(500);

        b.HasIndex(x => x.FormCode).IsUnique();
        b.HasIndex(x => x.ContractType);

        b.HasQueryFilter(x => !x.IsDeleted);
    }
}
