using ERPCore.Domain.Entities;
using ERPCore.Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace ERPCore.Infra.Persistence.Configurations;

public sealed class EmployeeBankDetailConfiguration : IEntityTypeConfiguration<EmployeeBankDetail>
{
    public void Configure(EntityTypeBuilder<EmployeeBankDetail> builder)
    {
        builder.ToTable("hr_employee_bank_details");
        builder.HasKey(b => b.EmployeeBankDetailId);

        builder.Property(b => b.BankName).IsRequired().HasMaxLength(200);
        builder.Property(b => b.BranchName).IsRequired().HasMaxLength(200);
        builder.Property(b => b.AccountNumber).IsRequired().HasMaxLength(50);
        builder.Property(b => b.AccountHolderName).IsRequired().HasMaxLength(200);
        builder.Property(b => b.SwiftCode).HasMaxLength(20);

        builder.Property(b => b.Status)
            .HasConversion<string>().HasMaxLength(20).IsRequired()
            .HasDefaultValue(EntityStatus.Active);

        builder.HasOne(b => b.Employee).WithMany()
            .HasForeignKey(b => b.EmployeeId).OnDelete(DeleteBehavior.Cascade);

        builder.Property(b => b.CreatedAt).IsRequired();
        builder.Property(b => b.RowVersion).IsRowVersion();

        builder.HasIndex(b => b.EmployeeId);
    }
}
