using Lada.Framework.Data.Domains.Finance;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Lada.Framework.Data.Mappings.EntityMappings.Finances
{
    public class BankMap : IEntityMappingConfiguration<Bank>
    {
        public void Map(EntityTypeBuilder<Bank> builder)
        {
            builder.HasKey(b => b.Id);
            builder.Property(b => b.Id).ValueGeneratedOnAdd();

            // Properties
            builder.Property(b => b.FullName)
                .HasMaxLength(512)
                .IsRequired();

            builder.Property(b => b.BrandName)
                .HasMaxLength(256)
                .IsRequired();


            // Indexes
            builder.HasIndex(b => b.BankCode)
                .HasDatabaseName("IX_Bank_BankCode");

            builder.HasIndex(b => b.BrandName)
                .HasDatabaseName("IX_Bank_BrandName");

            builder.HasIndex(b => b.DisplayOrder)
                .HasDatabaseName("IX_Bank_DisplayOrder");

            // Relationships
            builder.HasMany(b => b.BankAccounts)
                .WithOne(a => a.Bank)
                .HasForeignKey(a => a.BankId)
                .OnDelete(DeleteBehavior.Restrict);

            builder.ToTable("Bank");
        }
    }
}
