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

namespace JSMR.Infrastructure.Data.Configuration;

public sealed class EnglishVoiceWorkConfiguration : IEntityTypeConfiguration<EnglishVoiceWork>
{
    public void Configure(EntityTypeBuilder<EnglishVoiceWork> builder)
    {
        builder.ToTable("EnglishVoiceWorks");
        builder.HasKey(x => x.EnglishVoiceWorkId);

        builder.Property(x => x.ProductName).HasMaxLength(256);
        builder.Property(x => x.Description).HasMaxLength(512);

        builder.HasOne(x => x.VoiceWork)
            .WithMany(v => v.EnglishVoiceWorks)
            .HasForeignKey(x => x.VoiceWorkId)
            .OnDelete(DeleteBehavior.Cascade);

        builder.HasIndex(x => x.VoiceWorkId).IsUnique();
        builder.HasIndex(x => x.IsValid);
    }
}