using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Toolchains.InProcess.Emit;

namespace MaddoShared.Benchmarks;

/// <summary>
/// InProcess configuration for benchmarks requiring Windows-specific APIs
/// This avoids the net10.0-windows vs net10.0 compatibility issue
/// </summary>
public class InProcessConfig : ManualConfig
{
    public InProcessConfig()
    {
        AddLogger(ConsoleLogger.Default);
        AddExporter(HtmlExporter.Default);
        AddExporter(MarkdownExporter.GitHub);
        AddExporter(CsvExporter.Default);
        AddDiagnoser(MemoryDiagnoser.Default);
        
        // Add job with InProcess toolchain
        AddJob(Job.Default
            .WithToolchain(InProcessEmitToolchain.Instance)
            .WithWarmupCount(1)
            .WithIterationCount(3));
        
        // Configuration options
        WithOptions(ConfigOptions.DisableOptimizationsValidator);
        WithOptions(ConfigOptions.KeepBenchmarkFiles);
    }
}

/// <summary>
/// Custom configuration for image processing benchmarks
/// Uses InProcess toolchain to avoid net10.0-windows compatibility issues
/// </summary>
public class BenchmarkConfig : ManualConfig
{
    public BenchmarkConfig()
    {
        // Add console logger
        AddLogger(ConsoleLogger.Default);

        // Add exporters for different formats
        AddExporter(HtmlExporter.Default);
        AddExporter(MarkdownExporter.GitHub);
        AddExporter(CsvExporter.Default);
        AddExporter(RPlotExporter.Default);

        // Add diagnosers
        AddDiagnoser(MemoryDiagnoser.Default);
        AddDiagnoser(ThreadingDiagnoser.Default);

        // Add columns
        AddColumn(StatisticColumn.Mean);
        AddColumn(StatisticColumn.StdDev);
        AddColumn(StatisticColumn.Error);
        AddColumn(StatisticColumn.Min);
        AddColumn(StatisticColumn.Max);
        AddColumn(StatisticColumn.Median);
        AddColumn(BaselineRatioColumn.RatioMean);

        // Customize jobs with InProcess toolchain for Windows compatibility
        AddJob(Job.Default
            .WithToolchain(InProcessEmitToolchain.Instance)
            .WithWarmupCount(1)
            .WithIterationCount(3)
            .WithId("Quick"));

        AddJob(Job.Default
            .WithToolchain(InProcessEmitToolchain.Instance)
            .WithWarmupCount(2)
            .WithIterationCount(5)
            .WithId("Standard"));
    }

    /// <summary>
    /// Fast configuration for development and quick tests
    /// </summary>
    public static IConfig Fast => new ManualConfig()
        .AddLogger(ConsoleLogger.Default)
        .AddExporter(MarkdownExporter.GitHub)
        .AddDiagnoser(MemoryDiagnoser.Default)
        .AddJob(Job.Dry.WithToolchain(InProcessEmitToolchain.Instance)); // Very fast, but less accurate
}
