using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.Configuration;

namespace StellaOps.Configuration;

/// <summary>
/// Defines how default StellaOps configuration sources are composed.
/// </summary>
public sealed class StellaOpsConfigurationOptions
{
    public string? BasePath { get; set; } = Directory.GetCurrentDirectory();

    public bool IncludeJsonFiles { get; set; } = true;

    public bool IncludeYamlFiles { get; set; } = true;

    public bool IncludeEnvironmentVariables { get; set; } = true;

    public string? EnvironmentPrefix { get; set; }

    public IList<JsonConfigurationFile> JsonFiles { get; } = new List<JsonConfigurationFile>
    {
        new("appsettings.json", true, false),
        new("appsettings.local.json", true, false)
    };

    public IList<YamlConfigurationFile> YamlFiles { get; } = new List<YamlConfigurationFile>
    {
        new("appsettings.yaml", true),
        new("appsettings.local.yaml", true)
    };

    /// <summary>
    /// Optional hook to register additional configuration sources (e.g. module-specific YAML files).
    /// </summary>
    public Action<IConfigurationBuilder>? ConfigureBuilder { get; set; }

    /// <summary>
    /// Optional configuration section name used when binding strongly typed options.
    /// Null or empty indicates the root.
    /// </summary>
    public string? BindingSection { get; set; }
}

public sealed record JsonConfigurationFile(string Path, bool Optional = true, bool ReloadOnChange = false);

public sealed record YamlConfigurationFile(string Path, bool Optional = true);
