package com.ywt.outpatient.service.rpc.common;

import java.util.HashMap;
import java.util.Map;

/**
 * 后续统一用 BaseResponse 返回
 */
@Deprecated
public class ServiceResult {

    private int code;

    private String msg;

    private Map<String, Object> data;

    public ServiceResult() {
        this.data = new HashMap<>();
    }

    public ServiceResult succeed() {
        this.code = ServiceResultCode.SUCCEED;
        return this;
    }

    public ServiceResult succeed(String msg) {
        this.code = ServiceResultCode.SUCCEED;
        this.msg = msg;
        return this;
    }

    public ServiceResult succeed(Map<String, Object> data) {
        this.code = ServiceResultCode.SUCCEED;
        this.msg = "";
        this.data = data;
        return this;
    }

    public ServiceResult succeed(String msg, Map<String, Object> data) {
        this.code = ServiceResultCode.SUCCEED;
        this.msg = msg;
        this.data = data;
        return this;
    }

    public ServiceResult failed() {
        this.code = ServiceResultCode.FAILED;
        return this;
    }

    public ServiceResult failed(String msg) {
        this.code = ServiceResultCode.FAILED;
        this.msg = msg;
        return this;
    }

    public ServiceResult error() {
        this.code = ServiceResultCode.ERROR;
        return this;
    }

    public ServiceResult error(String msg) {
        this.code = ServiceResultCode.ERROR;
        this.msg = msg;
        return this;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public boolean success() {
        return this.code == ServiceResultCode.SUCCEED;
    }

    static class ServiceResultCode {
        static final int SUCCEED = 1;
        static final int FAILED = 0;
        static final int ERROR = 2;
    }


}
