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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

public class ProjectConfiguration : IEntityTypeConfiguration<Project>
{
    public void Configure(EntityTypeBuilder<Project> b)
    {
        b.ToTable("Projects");
        b.HasKey(x => x.Id);

        b.Property(x => x.Code).HasMaxLength(50).IsRequired();
        b.Property(x => x.Name).HasMaxLength(200).IsRequired();
        b.Property(x => x.BudgetTotal).HasPrecision(18, 2);
        b.Property(x => x.Note).HasMaxLength(1000);

        b.HasIndex(x => x.Code).IsUnique();

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