package cn.reghao.autodop.common.msg.rpc;

import lombok.Data;

import java.util.UUID;

/**
 * @author reghao
 * @date 2021-09-14 17:42:43
 */
@Data
public class RpcMsg {
    private String msgId;
    private RpcPayload rpcPayload;
    private RpcResult rpcResult;

    public RpcMsg(RpcPayload rpcPayload) {
        this.msgId = UUID.randomUUID().toString();
        this.rpcPayload = rpcPayload;
    }

    public RpcMsg(String msgId, RpcPayload rpcPayload, RpcResult rpcResult) {
        this.msgId = msgId;
        this.rpcPayload = rpcPayload;
        this.rpcResult = rpcResult;
    }

    public static RpcMsg callMsg(RpcPayload rpcPayload) {
        return new RpcMsg(rpcPayload);
    }

    public static RpcMsg resultMsg(RpcMsg callMsg, RpcResult rpcResult) {
        return new RpcMsg(callMsg.getMsgId(), callMsg.getRpcPayload(), rpcResult);
    }
}
