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

namespace Lada.Framework.Data.Mappings.EntityMappings.Trucks;

/// <summary>
/// Mapping configuration cho FuelRefillMedia
/// </summary>
public class FuelRefillMediaMap : IEntityMappingConfiguration<FuelRefillMedia>
{
    public void Map(EntityTypeBuilder<FuelRefillMedia> builder)
    {
        builder.ToTable("FuelRefillMedias");

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

        // Properties
        builder.Property(x => x.FuelRefillId).IsRequired();
        builder.Property(x => x.MediaId).IsRequired();
        builder.Property(x => x.MediaType).IsRequired();
        builder.Property(x => x.DisplayOrder).IsRequired();

        // Relationships
        builder.HasOne(x => x.FuelRefill)
            .WithMany(x => x.FuelRefillMedias)
            .HasForeignKey(x => x.FuelRefillId)
            .OnDelete(DeleteBehavior.Cascade);

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

        // Indexes
        builder.HasIndex(x => x.FuelRefillId)
            .HasDatabaseName("IX_FuelRefillMedias_FuelRefillId");

        builder.HasIndex(x => x.MediaId)
            .HasDatabaseName("IX_FuelRefillMedias_MediaId");
    }
}
