// <copyright file="BaseItemLiveTvExtrasConfiguration.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="BaseItemLiveTvExtras"/>.
/// </summary>
public class BaseItemLiveTvExtrasConfiguration : IEntityTypeConfiguration<BaseItemLiveTvExtras>
{
    /// <inheritdoc/>
    public void Configure(EntityTypeBuilder<BaseItemLiveTvExtras> builder)
    {
        ArgumentNullException.ThrowIfNull(builder);

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

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

        // Schedule range queries — mirrors the existing StartDate index on BaseItems
        builder.HasIndex(e => e.StartDate);
        builder.HasIndex(e => e.EndDate);
    }
}
