package cn.reghao.autodop.dagent.rpc.impl;

import cn.reghao.autodop.common.machine.Machine;
import cn.reghao.autodop.common.msg.rpc.RpcPayload;
import cn.reghao.autodop.common.msg.rpc.RpcResult;
import cn.reghao.autodop.common.msg.rpc.clazz.MachineRpcClazz;
import cn.reghao.jdkutil.serializer.JsonConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author reghao
 * @date 2020-12-30 10:26:47
 */
@Slf4j
@Component
public class MachineClazzRpcImpl {
    private final Machine machine;

    public MachineClazzRpcImpl(Machine machine) {
        this.machine = machine;
    }
    
    public RpcResult process(RpcPayload rpcPayload) {
        String method = rpcPayload.getMethod();
        String jsonParam = rpcPayload.getJsonParam();
        switch (MachineRpcClazz.valueOf(method)) {
            case stat:
                break;
            case shell:
                break;
            default:
        }
        return null;
    }


    public RpcResult stat() {
        return RpcResult.success(JsonConverter.objectToJson(machine.stat()));
    }

    public RpcResult shell(String script) {
        return RpcResult.success("");
    }
}
