using JSMR.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace JSMR.Infrastructure.Data.Configuration;

public sealed class EnglishTagConfiguration : IEntityTypeConfiguration<EnglishTag>
{
    public void Configure(EntityTypeBuilder<EnglishTag> builder)
    {
        builder.ToTable("EnglishTags");
        builder.HasKey(x => x.EnglishTagId);

        builder.Property(x => x.Name).IsRequired().HasMaxLength(128);

        builder.HasOne(x => x.Tag)
            .WithMany()
            .HasForeignKey(x => x.TagId)
            .OnDelete(DeleteBehavior.Cascade);

        builder.HasIndex(x => x.TagId).IsUnique();
        builder.HasIndex(x => x.Name);
    }
}