// <copyright file="BaseItemTvExtrasConfiguration.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

namespace Jellyfin.Database.Implementations.ModelConfiguration;

using System;
using Jellyfin.Database.Implementations.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

/// <summary>
/// EF Core configuration for <see cref="BaseItemTvExtras"/>.
/// </summary>
public class BaseItemTvExtrasConfiguration : IEntityTypeConfiguration<BaseItemTvExtras>
{
    /// <inheritdoc/>
    public void Configure(EntityTypeBuilder<BaseItemTvExtras> builder)
    {
        ArgumentNullException.ThrowIfNull(builder);

        builder.HasKey(e => e.ItemId);
        builder.ToTable("base_item_tv_extras", "library");

        builder.HasOne(e => e.Item)
            .WithOne(e => e.TvExtras)
            .HasForeignKey<BaseItemTvExtras>(e => e.ItemId)
            .OnDelete(DeleteBehavior.Cascade);

        builder.HasIndex(e => e.SeriesId);
        builder.HasIndex(e => e.SeriesPresentationUniqueKey);
    }
}
