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 PremiseFinancialMap : IEntityMappingConfiguration<PremiseFinancial>
    {
        public void Map(EntityTypeBuilder<PremiseFinancial> builder)
        {
            builder.ToTable("PremiseFinancials");

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

            // Properties
            builder.Property(x => x.PremiseId).IsRequired();
            builder.Property(x => x.AskingRent).HasColumnType("decimal(18,2)");
            builder.Property(x => x.NegotiatedRent).HasColumnType("decimal(18,2)");
            builder.Property(x => x.LegalNote).HasMaxLength(4000);

            // Relationships (1-1 with Premise)
            builder.HasOne(x => x.Premise)
                .WithOne(x => x.Financial)
                .HasForeignKey<PremiseFinancial>(x => x.PremiseId)
                .OnDelete(DeleteBehavior.Cascade);

            // Unique index for 1-1 relationship
            builder.HasIndex(x => x.PremiseId)
                .IsUnique()
                .HasDatabaseName("IX_PremiseFinancials_PremiseId");
        }
    }
}
