use ops_keeper::types::PendingOp;

use crate::{error::ControllerError, orchestrator::OrchestratorClient};

pub mod deploy;
pub mod drain;
pub mod restart;
pub mod rollback;
pub mod scale;
pub mod secret_update;

/// Dispatch a validated op to the appropriate handler.
pub async fn dispatch(
    op: &PendingOp,
    orc: &OrchestratorClient,
) -> Result<(), ControllerError> {
    match op.op_type.as_str() {
        "deploy"        => deploy::run(op, orc).await,
        "scale"         => scale::run(op, orc).await,
        "restart"       => restart::run(op, orc).await,
        "secret_update" => secret_update::run(op, orc).await,
        "drain"         => drain::run(op, orc).await,
        "rollback"      => rollback::run(op, orc).await,
        other => Err(ControllerError::Orchestrator(format!("unknown op_type '{other}'"))),
    }
}
