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

namespace CMSMicroservice.Infrastructure.Persistence.Configurations;

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

        builder.Property(x => x.PageKey)
            .IsRequired()
            .HasMaxLength(50);

        builder.Property(x => x.Title)
            .IsRequired()
            .HasMaxLength(200);

        builder.Property(x => x.MetaDescription)
            .HasMaxLength(300);

        builder.Property(x => x.HeroTitle)
            .HasMaxLength(200);

        builder.Property(x => x.HeroSubtitle)
            .HasMaxLength(500);

        builder.Property(x => x.IsActive)
            .IsRequired()
            .HasDefaultValue(true);

        // SettingsJson — ستون JSON بدون محدودیت طول
        builder.Property(x => x.SettingsJson)
            .HasColumnType("nvarchar(max)");

        // ایندکس یکتا روی PageKey
        builder.HasIndex(x => x.PageKey)
            .IsUnique()
            .HasDatabaseName("IX_SitePageSettings_PageKey");
    }
}
