using CMSMicroservice.Domain.Entities.Content;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CMSMicroservice.Infrastructure.Persistence.Configurations.Content;

public class SitePageSectionConfiguration : IEntityTypeConfiguration<SitePageSection>
{
    public void Configure(EntityTypeBuilder<SitePageSection> builder)
    {
        builder.ToTable("SitePageSections");
        builder.HasKey(x => x.Id);

        builder.Property(x => x.SitePageId).IsRequired();
        builder.Property(x => x.SectionKey).IsRequired().HasMaxLength(100);
        builder.Property(x => x.Title).IsRequired().HasMaxLength(200);
        builder.Property(x => x.Subtitle).HasMaxLength(300);
        builder.Property(x => x.IconName).HasMaxLength(100);
        builder.Property(x => x.ImagePath);
        builder.Property(x => x.ImageThumbnailPath);
        builder.Property(x => x.SortOrder).IsRequired().HasDefaultValue(0);
        builder.Property(x => x.IsActive).IsRequired().HasDefaultValue(true);

        builder.HasOne(d => d.SitePage)
            .WithMany(p => p.Sections)
            .HasForeignKey(d => d.SitePageId);

        // Indexes
        builder.HasIndex(x => new { x.SitePageId, x.SectionKey })
            .HasDatabaseName("IX_SitePageSections_PageId_SectionKey");
    }
}
