using Domain.Entities.Forum.Posts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.Persistence.Configurations.Forum.Posts;

public sealed class TagConfiguration : IEntityTypeConfiguration<Tag>
{
    public void Configure(EntityTypeBuilder<Tag> builder)
    {
        builder.HasIndex(x => x.Name).IsUnique();
        builder.HasIndex(x => x.Slug).IsUnique();
        builder.HasIndex(x => x.UsageCount);

        builder.HasMany(x => x.PostTag).WithOne(x => x.Tag).HasForeignKey(x => x.TagID).OnDelete(DeleteBehavior.Cascade);

        builder.ToTable("Tag", x => x.HasComment("태그"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
    }
}
