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

namespace Lada.Framework.Data.Mappings.EntityMappings.ErrorReports
{
    public class ErrorReportMediaMap : IEntityMappingConfiguration<ErrorReportMedia>
    {
        public void Map(EntityTypeBuilder<ErrorReportMedia> builder)
        {
            builder.HasKey(erm => erm.Id);
            builder.Property(erm => erm.Id).UseIdentityColumn(1);

            // Cấu hình các thuộc tính
            builder.Property(erm => erm.SystemPath)
                .HasMaxLength(2500)
                .IsRequired();

            builder.Property(erm => erm.OriginalFileName)
                .HasMaxLength(255)
                .IsRequired();

            builder.Property(erm => erm.ContentType)
                .HasMaxLength(100)
                .IsRequired();

            builder.Property(erm => erm.Description)
                .HasMaxLength(500);

            // Quan hệ với ErrorReport (nhiều-1)
            builder.HasOne(erm => erm.ErrorReport)
                .WithMany(er => er.ErrorReportMedias)
                .HasForeignKey(erm => erm.ErrorReportId)
                .OnDelete(DeleteBehavior.Cascade);

            // Index
            builder.HasIndex(erm => erm.ErrorReportId);
            builder.HasIndex(erm => erm.DisplayOrder);

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