use std::path::PathBuf;

use super::super::{CompareCommand, usage_error};

pub(super) fn parse_compare_command(
    args: &[String],
) -> Result<CompareCommand, Box<dyn std::error::Error>> {
    match args {
        [subcommand, left_path, right_path] if subcommand == "compare-region-fixed-row-runs" => {
            Ok(CompareCommand::CompareRegionFixedRowRuns {
                left_path: left_path.into(),
                right_path: right_path.into(),
            })
        }
        [subcommand, smp_paths @ ..]
            if subcommand == "compare-classic-profile" && smp_paths.len() >= 2 =>
        {
            Ok(CompareCommand::CompareClassicProfile {
                smp_paths: smp_paths.iter().map(PathBuf::from).collect(),
            })
        }
        [subcommand, smp_paths @ ..]
            if subcommand == "compare-105-profile" && smp_paths.len() >= 2 =>
        {
            Ok(CompareCommand::CompareRt3105Profile {
                smp_paths: smp_paths.iter().map(PathBuf::from).collect(),
            })
        }
        [subcommand, smp_paths @ ..]
            if subcommand == "compare-candidate-table" && smp_paths.len() >= 2 =>
        {
            Ok(CompareCommand::CompareCandidateTable {
                smp_paths: smp_paths.iter().map(PathBuf::from).collect(),
            })
        }
        [subcommand, smp_paths @ ..]
            if subcommand == "compare-recipe-book-lines" && smp_paths.len() >= 2 =>
        {
            Ok(CompareCommand::CompareRecipeBookLines {
                smp_paths: smp_paths.iter().map(PathBuf::from).collect(),
            })
        }
        [subcommand, smp_paths @ ..]
            if subcommand == "compare-setup-payload-core" && smp_paths.len() >= 2 =>
        {
            Ok(CompareCommand::CompareSetupPayloadCore {
                smp_paths: smp_paths.iter().map(PathBuf::from).collect(),
            })
        }
        [subcommand, smp_paths @ ..]
            if subcommand == "compare-setup-launch-payload" && smp_paths.len() >= 2 =>
        {
            Ok(CompareCommand::CompareSetupLaunchPayload {
                smp_paths: smp_paths.iter().map(PathBuf::from).collect(),
            })
        }
        [subcommand, smp_paths @ ..]
            if subcommand == "compare-post-special-conditions-scalars" && smp_paths.len() >= 2 =>
        {
            Ok(CompareCommand::ComparePostSpecialConditionsScalars {
                smp_paths: smp_paths.iter().map(PathBuf::from).collect(),
            })
        }
        _ => usage_error(),
    }
}
