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

namespace Lada.Framework.Data.Mappings.EntityMappings.Trucks
{
    /// <summary>
    /// Entity mapping configuration cho TruckActivityMedia
    /// </summary>
    public class TruckActivityMediaMap : IEntityMappingConfiguration<TruckActivityMedia>
    {
        public void Map(EntityTypeBuilder<TruckActivityMedia> builder)
        {
            builder.HasKey(o => o.Id);
            builder.Property(o => o.Id).UseIdentityColumn(1);

            // Cấu hình các thuộc tính
            builder.Property(o => o.TruckActivityId).IsRequired();
            builder.Property(o => o.MediaId).IsRequired();
            builder.Property(o => o.MediaType).IsRequired();
            builder.Property(o => o.DisplayOrder).HasDefaultValue(0);

            // Cấu hình relationships
            builder.HasOne(o => o.TruckActivity)
                   .WithMany()
                   .HasForeignKey(o => o.TruckActivityId)
                   .OnDelete(DeleteBehavior.Cascade);

            builder.HasOne(o => o.Media)
                   .WithMany()
                   .HasForeignKey(o => o.MediaId)
                   .OnDelete(DeleteBehavior.Restrict);

            // Cấu hình indexes
            builder.HasIndex(o => o.TruckActivityId);
            builder.HasIndex(o => o.MediaId);

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