using AyCode.Interfaces.Addresses;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace AyCode.Database.ModelBuilders.Profiles;

public static class AcProfileEntityTypeBuilderExtensions
{
    public static void BuildEntityToAddressRelation<TAddressRelation, TAddress>(this EntityTypeBuilder<TAddressRelation> modelBuilder, bool autoInclude = true) 
        where TAddressRelation : class, IAcAddressRelation<TAddress> 
        where TAddress : class, IAcAddress
    {
        //modelBuilder.HasOne(e => e.Address).WithOne().HasForeignKey<TAddressRelation>(e => e.AddressId);

        modelBuilder.HasOne(x => x.Address).WithOne().OnDelete(DeleteBehavior.Cascade);
        modelBuilder.Navigation(e => e.Address).AutoInclude(autoInclude).IsRequired();
    }
}