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

pub(super) fn parse_fixture_state_command(
    args: &[String],
) -> Result<FixtureStateCommand, Box<dyn std::error::Error>> {
    match args {
        [subcommand, fixture_path] if subcommand == "validate-fixture" => {
            Ok(FixtureStateCommand::ValidateFixture {
                fixture_path: fixture_path.into(),
            })
        }
        [subcommand, fixture_path] if subcommand == "summarize-fixture" => {
            Ok(FixtureStateCommand::SummarizeFixture {
                fixture_path: fixture_path.into(),
            })
        }
        [subcommand, fixture_path, output_path] if subcommand == "export-fixture-state" => {
            Ok(FixtureStateCommand::ExportFixtureState {
                fixture_path: fixture_path.into(),
                output_path: output_path.into(),
            })
        }
        [subcommand, left_path, right_path] if subcommand == "diff-state" => {
            Ok(FixtureStateCommand::DiffState {
                left_path: left_path.into(),
                right_path: right_path.into(),
            })
        }
        [subcommand, snapshot_path] if subcommand == "summarize-state" => {
            Ok(FixtureStateCommand::SummarizeState {
                snapshot_path: snapshot_path.into(),
            })
        }
        [subcommand, input_path, output_path] if subcommand == "snapshot-state" => {
            Ok(FixtureStateCommand::SnapshotState {
                input_path: input_path.into(),
                output_path: output_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "summarize-save-load" => {
            Ok(FixtureStateCommand::SummarizeSaveLoad {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path] if subcommand == "load-save-slice" => {
            Ok(FixtureStateCommand::LoadSaveSlice {
                smp_path: smp_path.into(),
            })
        }
        [subcommand, smp_path, output_path] if subcommand == "snapshot-save-state" => {
            Ok(FixtureStateCommand::SnapshotSaveState {
                smp_path: smp_path.into(),
                output_path: output_path.into(),
            })
        }
        [subcommand, smp_path, output_path] if subcommand == "export-save-slice" => {
            Ok(FixtureStateCommand::ExportSaveSlice {
                smp_path: smp_path.into(),
                output_path: output_path.into(),
            })
        }
        [subcommand, snapshot_path, save_slice_path, output_path]
            if subcommand == "export-overlay-import" =>
        {
            Ok(FixtureStateCommand::ExportOverlayImport {
                snapshot_path: snapshot_path.into(),
                save_slice_path: save_slice_path.into(),
                output_path: output_path.into(),
            })
        }
        _ => usage_error(),
    }
}
