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

pub(super) fn parse_inspect_command(
    args: &[String],
) -> Result<InspectCommand, Box<dyn std::error::Error>> {
    match args {
        [subcommand, smp_path] if subcommand == "inspect-smp" => Ok(InspectCommand::InspectSmp {
            smp_path: smp_path.into(),
        }),
        [subcommand, smp_path] if subcommand == "inspect-candidate-table" => {
            Ok(InspectCommand::InspectCandidateTable {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, root_path] if subcommand == "inspect-compact-event-dispatch-cluster" => {
            Ok(InspectCommand::InspectCompactEventDispatchCluster {
                root_path: root_path.into(),
            })
        }
        [subcommand, root_path]
            if subcommand == "inspect-compact-event-dispatch-cluster-counts" =>
        {
            Ok(InspectCommand::InspectCompactEventDispatchClusterCounts {
                root_path: root_path.into(),
            })
        }
        [subcommand, root_path] if subcommand == "inspect-map-title-hints" => {
            Ok(InspectCommand::InspectMapTitleHints {
                root_path: root_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "inspect-save-company-chairman" => {
            Ok(InspectCommand::InspectSaveCompanyChairman {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "inspect-save-placed-structure-triplets" => {
            Ok(InspectCommand::InspectSavePlacedStructureTriplets {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "inspect-periodic-company-service-trace" => {
            Ok(InspectCommand::InspectPeriodicCompanyServiceTrace {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "inspect-region-service-trace" => {
            Ok(InspectCommand::InspectRegionServiceTrace {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "inspect-infrastructure-asset-trace" => {
            Ok(InspectCommand::InspectInfrastructureAssetTrace {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "inspect-save-region-queued-notice-records" => {
            Ok(InspectCommand::InspectSaveRegionQueuedNoticeRecords {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "inspect-placed-structure-dynamic-side-buffer" => {
            Ok(InspectCommand::InspectPlacedStructureDynamicSideBuffer {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "inspect-unclassified-save-collections" => {
            Ok(InspectCommand::InspectUnclassifiedSaveCollections {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, pk4_path] if subcommand == "inspect-pk4" => Ok(InspectCommand::InspectPk4 {
            pk4_path: pk4_path.into(),
        }),
        [subcommand, cargo_types_dir] if subcommand == "inspect-cargo-types" => {
            Ok(InspectCommand::InspectCargoTypes {
                cargo_types_dir: cargo_types_dir.into(),
            })
        }
        [subcommand, building_types_dir] if subcommand == "inspect-building-type-sources" => {
            Ok(InspectCommand::InspectBuildingTypeSources {
                building_types_dir: building_types_dir.into(),
                bindings_path: None,
            })
        }
        [subcommand, building_types_dir, bindings_path]
            if subcommand == "inspect-building-type-sources" =>
        {
            Ok(InspectCommand::InspectBuildingTypeSources {
                building_types_dir: building_types_dir.into(),
                bindings_path: Some(bindings_path.into()),
            })
        }
        [subcommand, cargo_skin_pk4_path] if subcommand == "inspect-cargo-skins" => {
            Ok(InspectCommand::InspectCargoSkins {
                cargo_skin_pk4_path: cargo_skin_pk4_path.into(),
            })
        }
        [subcommand, cargo_types_dir, cargo_skin_pk4_path]
            if subcommand == "inspect-cargo-economy-sources" =>
        {
            Ok(InspectCommand::InspectCargoEconomySources {
                cargo_types_dir: cargo_types_dir.into(),
                cargo_skin_pk4_path: cargo_skin_pk4_path.into(),
            })
        }
        [subcommand, cargo_types_dir, cargo_skin_pk4_path]
            if subcommand == "inspect-cargo-production-selector" =>
        {
            Ok(InspectCommand::InspectCargoProductionSelector {
                cargo_types_dir: cargo_types_dir.into(),
                cargo_skin_pk4_path: cargo_skin_pk4_path.into(),
            })
        }
        [subcommand, cargo_types_dir, cargo_skin_pk4_path]
            if subcommand == "inspect-cargo-price-selector" =>
        {
            Ok(InspectCommand::InspectCargoPriceSelector {
                cargo_types_dir: cargo_types_dir.into(),
                cargo_skin_pk4_path: cargo_skin_pk4_path.into(),
            })
        }
        [subcommand, win_path] if subcommand == "inspect-win" => Ok(InspectCommand::InspectWin {
            win_path: win_path.into(),
        }),
        [subcommand, pk4_path, entry_name, output_path] if subcommand == "extract-pk4-entry" => {
            Ok(InspectCommand::ExtractPk4Entry {
                pk4_path: pk4_path.into(),
                entry_name: entry_name.clone(),
                output_path: output_path.into(),
            })
        }
        [subcommand, exe_path] if subcommand == "inspect-campaign-exe" => {
            Ok(InspectCommand::InspectCampaignExe {
                exe_path: exe_path.into(),
            })
        }
        [subcommand, smp_path, output_path] if subcommand == "export-profile-block" => {
            Ok(InspectCommand::ExportProfileBlock {
                smp_path: smp_path.into(),
                output_path: output_path.into(),
            })
        }
        _ => usage_error(),
    }
}
