use crate::logic::{
    game::{GameInstance, LogicError},
    procedure::ProcedureAction,
};

use super::*;

pub async fn on_perform_trigger(
    _session: &NetSession,
    player: &mut Player,
    req: PerformTriggerCsReq,
) -> NetResult<PerformTriggerScRsp> {
    if let GameInstance::Fresh(fresh_game) = &mut player.game_instance {
        fresh_game
            .procedure_mgr
            .on_action(ProcedureAction::PerformTrigger)
            .map_err(LogicError::from)?;
    }

    Ok(PerformTriggerScRsp {
        retcode: Retcode::RetSucc.into(),
        perform_uid: ((req.perform_type as i64) << 32) | req.perform_id as i64,
    })
}

pub async fn on_perform_end(
    _session: &NetSession,
    player: &mut Player,
    _req: PerformEndCsReq,
) -> NetResult<PerformEndScRsp> {
    if let GameInstance::Fresh(fresh_game) = &mut player.game_instance {
        fresh_game
            .procedure_mgr
            .on_action(ProcedureAction::PerformEnd)
            .map_err(LogicError::from)?;
    }

    Ok(PerformEndScRsp {
        retcode: Retcode::RetSucc.into(),
    })
}

pub async fn on_perform_jump(
    _session: &NetSession,
    _player: &mut Player,
    _req: PerformJumpCsReq,
) -> NetResult<PerformJumpScRsp> {
    Ok(PerformJumpScRsp {
        retcode: Retcode::RetSucc.into(),
    })
}
