// Copyright 2025 Chisomo Makombo Sakala
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use clap::Parser;
use clap::Subcommand;
use std::path::PathBuf;

/// Algorithm Benchmarking Orchestrator
#[derive(Debug, Parser)]
#[command(version, about = "Algorithm Benchmarking Orchestrator")]
pub struct Cli {
  #[command(subcommand)]
  pub command: Commands,
}

/// Defines the main subcommands: `build` and `run`.
#[derive(Debug, Subcommand)]
pub enum Commands {
  /// Scans the components directory and builds all found components.
  Build {
    /// Root directory containing component subdirectories.
    #[arg(long, default_value = ".")]
    components_dir: PathBuf,

    /// Output path for the build manifest.
    #[arg(long, default_value = "impa_manifest.json")]
    manifest_path: PathBuf,
  },

  /// Runs the benchmark using built components.
  Run(RunArgs),
}

/// Arguments for the `run` subcommand.
#[derive(Debug, clap::Args)]
pub struct RunArgs {
  /// JSON string mapping languages to lists of algorithm names to run.
  /// Example: '{"cpp": ["std::sort"], "lean": ["List.mergeSort"]}'
  #[arg(long, required = true)]
  pub algorithms: String,

  /// Seed for the random number generator (if a generator is used).
  #[arg(long)]
  pub seed: Option<u64>,

  /// Name of the generator component to use, or 'none' for self-contained algorithms.
  #[arg(long, required = true)]
  pub generator: String,

  // --- High-Priority Overrides ---
  /// Override the path to the generator executable.
  #[arg(long)]
  pub generator_override_path: Option<PathBuf>,

  /// Override paths to algorithm executables as a JSON map.
  /// Example: '{"cpp": "./my_cpp_exe", "lean": "./my_lean_exe"}'
  #[arg(long)]
  pub algorithm_override_paths: Option<String>,

  /// Path to the build manifest (generated by the 'build' command).
  #[arg(long, default_value = "impa_manifest.json")]
  pub manifest_path: PathBuf,

  // --- Passthrough Arguments ---
  /// All remaining arguments are passed to the data generator.
  #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
  pub generator_args: Vec<String>,
}
