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

namespace Jellyfin.Database.Implementations.DbConfiguration;

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

/// <summary>
/// Options to configure jellyfins managed database.
/// </summary>
public class DatabaseConfigurationOptions
{
    /// <summary>
    /// Initializes a new instance of the <see cref="DatabaseConfigurationOptions"/> class.
    /// </summary>
    public DatabaseConfigurationOptions()
    {
        // Default to PostgreSQL
        DatabaseType = "Jellyfin-PostgreSQL";
        LockingBehavior = DatabaseLockingBehaviorTypes.NoLock;

        // Set up default PostgreSQL configuration
        CustomProviderOptions = new CustomDatabaseOptions
        {
            PluginName = "Jellyfin-PostgreSQL",
            PluginAssembly = "Jellyfin.Database.Providers.Postgres",
            ConnectionString = "Host=localhost;Port=5432;Database=jellyfin;Username=jellyfin;Password=jellyfin"
        };

        // Set up default backup options
        BackupOptions = new DatabaseBackupOptions
        {
            PgDumpPath = "pg_dump",
            PgRestorePath = "pg_restore",
            BackupFormat = "custom",
            IncludeBlobs = true,
            CompressionLevel = 6,
            TimeoutSeconds = 1800,
            VerboseOutput = true
        };
    }

    /// <summary>
    /// Gets or Sets the type of database jellyfin should use.
    /// </summary>
    public string? DatabaseType { get; set; }

    /// <summary>
    /// Gets or sets the options required to use a custom database provider.
    /// </summary>
    public CustomDatabaseOptions? CustomProviderOptions { get; set; }

    /// <summary>
    /// Gets or Sets the kind of locking behavior jellyfin should perform. Possible options are "NoLock", "Pessimistic", "Optimistic".
    /// Defaults to "NoLock".
    /// </summary>
    public DatabaseLockingBehaviorTypes LockingBehavior { get; set; }

    /// <summary>
    /// Gets or sets the backup configuration options.
    /// </summary>
    public DatabaseBackupOptions? BackupOptions { get; set; }

    /// <summary>
    /// Gets or sets preset configurations for quick switching between database providers.
    /// These are stored in the configuration file for reference but not used unless DatabaseType is set to match a preset key.
    /// </summary>
    [SuppressMessage("Design", "CA2227:Collection properties should be read-only", Justification = "JSON deserialization requires settable property")]
    [SuppressMessage("Naming", "CA1002:Do not expose generic lists", Justification = "System.Text.Json works best with List<T> for array deserialization")]
    public List<PresetConfigurationItem>? PresetConfigurations { get; set; }
}
