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

namespace CMSMicroservice.Infrastructure.Persistence.Configurations.Blog;

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

        builder.Property(x => x.BlogPostId).IsRequired();
        builder.Property(x => x.ImagePath).IsRequired();
        builder.Property(x => x.ThumbnailPath).IsRequired();
        builder.Property(x => x.AltText).HasMaxLength(200);
        builder.Property(x => x.Caption).HasMaxLength(300);
        builder.Property(x => x.SortOrder).IsRequired().HasDefaultValue(0);

        builder.HasOne(d => d.BlogPost)
            .WithMany(p => p.BlogPostImages)
            .HasForeignKey(d => d.BlogPostId);
    }
}
