use std::collections::BTreeMap;

use serde::Serialize;

#[derive(Debug, Clone, Serialize)]
pub struct ReportPalette {
    pub athena_hex: String,
    pub better_hex: String,
    pub delta_positive_hex: String,
    pub delta_negative_hex: String,
    pub neutral_hex: String,
    pub background_hex: String,
}

#[derive(Debug, Clone, Serialize)]
pub struct BenchmarkArgon2ProfileArtifact {
    pub memory_cost: u32,
    pub time_cost: u32,
    pub parallelism: u32,
    pub source_label: String,
}

#[derive(Debug, Clone, Serialize)]
pub struct BenchmarkSampleArtifact {
    pub rust_ms: f64,
    pub reference_ms: f64,
    pub rust_status: u16,
    pub reference_status: u16,
}

#[derive(Debug, Clone, Serialize)]
pub struct BenchmarkMetricsArtifact {
    pub rust_avg_ms: f64,
    pub rust_p50_ms: f64,
    pub rust_p95_ms: f64,
    pub rust_min_ms: f64,
    pub rust_max_ms: f64,
    pub reference_avg_ms: f64,
    pub reference_p50_ms: f64,
    pub reference_p95_ms: f64,
    pub reference_min_ms: f64,
    pub reference_max_ms: f64,
    pub delta_avg_ms: f64,
    pub rust_status_counts: BTreeMap<u16, usize>,
    pub reference_status_counts: BTreeMap<u16, usize>,
}

#[derive(Debug, Clone, Serialize)]
pub struct BenchmarkRunArtifact {
    pub run_index: usize,
    pub samples: usize,
    pub metrics: Option<BenchmarkMetricsArtifact>,
    pub skip_reason: Option<String>,
    pub raw_samples: Vec<BenchmarkSampleArtifact>,
}

#[derive(Debug, Clone, Serialize)]
pub struct BenchmarkScenarioArtifact {
    pub id: String,
    pub label: String,
    pub total_samples: usize,
    pub completed_runs: usize,
    pub suite_repeats: usize,
    pub aggregate_metrics: Option<BenchmarkMetricsArtifact>,
    pub skip_reasons: Vec<String>,
    pub runs: Vec<BenchmarkRunArtifact>,
}

#[derive(Debug, Clone, Serialize)]
pub struct BenchmarkSuiteArtifact {
    pub title: String,
    pub generated_at: String,
    pub iterations_per_run: usize,
    pub warmup_iterations: usize,
    pub suite_repeats: usize,
    pub rust_server_label: String,
    pub reference_server_label: String,
    pub reference_origin: String,
    pub markdown_report_path: String,
    pub json_report_path: String,
    pub html_report_path: String,
    pub argon2_profile: BenchmarkArgon2ProfileArtifact,
    pub palette: ReportPalette,
    pub scenarios: Vec<BenchmarkScenarioArtifact>,
}
