mod compare;
mod fixture_state;
mod inspect;
mod scan;

use super::{Command, RuntimeCommand, usage_error};

pub(super) fn parse_runtime_command(
    args: &[String],
) -> Result<Command, Box<dyn std::error::Error>> {
    let [subcommand, ..] = args else {
        return usage_error();
    };

    let runtime_command = match subcommand.as_str() {
        "validate-fixture"
        | "summarize-fixture"
        | "export-fixture-state"
        | "diff-state"
        | "summarize-state"
        | "snapshot-state"
        | "summarize-save-load"
        | "load-save-slice"
        | "snapshot-save-state"
        | "export-save-slice"
        | "export-overlay-import" => {
            RuntimeCommand::FixtureState(fixture_state::parse_fixture_state_command(args)?)
        }
        "inspect-smp"
        | "inspect-candidate-table"
        | "inspect-compact-event-dispatch-cluster"
        | "inspect-compact-event-dispatch-cluster-counts"
        | "inspect-map-title-hints"
        | "inspect-save-company-chairman"
        | "inspect-save-placed-structure-triplets"
        | "inspect-periodic-company-service-trace"
        | "inspect-region-service-trace"
        | "inspect-infrastructure-asset-trace"
        | "inspect-save-region-queued-notice-records"
        | "inspect-placed-structure-dynamic-side-buffer"
        | "inspect-unclassified-save-collections"
        | "inspect-pk4"
        | "inspect-cargo-types"
        | "inspect-building-type-sources"
        | "inspect-cargo-skins"
        | "inspect-cargo-economy-sources"
        | "inspect-cargo-production-selector"
        | "inspect-cargo-price-selector"
        | "inspect-win"
        | "extract-pk4-entry"
        | "inspect-campaign-exe"
        | "export-profile-block" => RuntimeCommand::Inspect(inspect::parse_inspect_command(args)?),
        "compare-region-fixed-row-runs"
        | "compare-classic-profile"
        | "compare-105-profile"
        | "compare-candidate-table"
        | "compare-recipe-book-lines"
        | "compare-setup-payload-core"
        | "compare-setup-launch-payload"
        | "compare-post-special-conditions-scalars" => {
            RuntimeCommand::Compare(compare::parse_compare_command(args)?)
        }
        "scan-candidate-table-headers"
        | "scan-candidate-table-named-runs"
        | "scan-special-conditions"
        | "scan-aligned-runtime-rule-band"
        | "scan-post-special-conditions-scalars"
        | "scan-post-special-conditions-tail"
        | "scan-recipe-book-lines" => RuntimeCommand::Scan(scan::parse_scan_command(args)?),
        _ => return usage_error(),
    };

    Ok(Command::Runtime(runtime_command))
}
