// <copyright file="LibraryOptionsEntityConfiguration.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>
/// LibraryOptionsEntity Configuration.
/// </summary>
public class LibraryOptionsEntityConfiguration : IEntityTypeConfiguration<LibraryOptionsEntity>
{
    /// <inheritdoc/>
    public void Configure(EntityTypeBuilder<LibraryOptionsEntity> builder)
    {
        ArgumentNullException.ThrowIfNull(builder);
        builder.ToTable("library_options", "library");
        builder.HasKey(e => e.LibraryPath);
        builder.Property(e => e.LibraryPath).IsRequired();
        builder.Property(e => e.OptionsJson).IsRequired().HasColumnType("jsonb");
        builder.Property(e => e.Version).HasDefaultValue(1);
        builder.Property(e => e.DateCreated).ValueGeneratedOnAdd();
        builder.Property(e => e.DateModified).ValueGeneratedOnAdd();
        builder.HasIndex(e => e.DateModified).IsDescending();
    }
}
