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

namespace Lada.Framework.Data.Mappings.EntityMappings.Finance
{
    public class CustomerReconciliationLogMap : IEntityMappingConfiguration<CustomerReconciliationLog>
    {
        public void Map(EntityTypeBuilder<CustomerReconciliationLog> builder)
        {
            builder.ToTable("CustomerReconciliationLogs");

            // Primary Key
            builder.HasKey(x => x.Id);

            // Properties
            builder.Property(x => x.ActorUsername)
                .HasMaxLength(128)
                .IsRequired();

            builder.Property(x => x.OldStatus)
                .HasMaxLength(64);

            builder.Property(x => x.NewStatus)
                .HasMaxLength(64);

            builder.Property(x => x.Note)
                .HasMaxLength(2048);

            builder.Property(x => x.Metadata)
                .HasMaxLength(4000);

            builder.Property(x => x.CreatedByUserName)
                .HasMaxLength(128)
                .IsRequired();

            // Relationships
            builder.HasOne(x => x.CustomerReconciliationSlip)
                .WithMany(x => x.Logs)
                .HasForeignKey(x => x.CustomerReconciliationSlipId)
                .OnDelete(DeleteBehavior.Cascade);

            // Indexes
            builder.HasIndex(x => x.CustomerReconciliationSlipId);

            builder.HasIndex(x => x.ActorId);

            builder.HasIndex(x => x.ActionType);

            builder.HasIndex(x => x.CreatedTime);
        }
    }
}
