using Lada.Framework.Data.Domains.Premises;
using Lada.Framework.Data.Mappings;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Lada.Framework.Data.Mappings.EntityMappings.Premises
{
    public class PremiseScoringOptionMap : IEntityMappingConfiguration<PremiseScoringOption>
    {
        public void Map(EntityTypeBuilder<PremiseScoringOption> builder)
        {
            builder.ToTable("PremiseScoringOptions");

            builder.HasKey(x => x.Id);

            // Properties
            builder.Property(x => x.CriteriaId).IsRequired();
            builder.Property(x => x.Label).HasMaxLength(200).IsRequired();
            builder.Property(x => x.MinValue).HasColumnType("decimal(18,2)");
            builder.Property(x => x.MaxValue).HasColumnType("decimal(18,2)");
            builder.Property(x => x.Score).IsRequired();

            // Relationships
            builder.HasOne(x => x.Criteria)
                .WithMany(x => x.Options)
                .HasForeignKey(x => x.CriteriaId)
                .OnDelete(DeleteBehavior.Cascade);

            // Indexes
            builder.HasIndex(x => x.CriteriaId)
                .HasDatabaseName("IX_PremiseScoringOptions_CriteriaId");
        }
    }
}
