const system = require("../../system");
class StateBase{
  constructor(api){
    this.actions=api;
    this.curState=null;
  }
  //改变状态
  setState(curState){
    this.curState=curState;
    return this;
  }
  //执行操作
  async doAction(params){
    try {
      if(this.actions[this.curState]){
        return await this.actions[this.curState][this.curState].apply(this,[params]);
      }else{
        return system.getResult(-1,`系统错误 未找到处理器`);
      }
    } catch (error) {
      return system.getResult(-1,`系统错误 错误信息 ${error}`);
    }
  }
}

module.exports = StateBase;
