package com.dxhy.common.auth;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author baiyun
 * @Title: DubboManagerService
 * @ProjectName bwserver
 * @date 2019/6/3  9:40
 * @Description:结果集
 */
@Data
public class Result<T> implements Serializable {

    public Result() {
    }

    public Result(String code, T content, String msg) {
        this.setCode(code);
        this.setResult(content);
        this.setMsg(msg);
    }

    /**
     * code
     */
    private String code;

    /**
     * 对订单暴露返回
     */
    private T result;
    /**
     * msg result message
     */
    private String msg;

    private String redirectUrl;

    /**
     * error message list
     * Used when batch processing
     */
    private List<String> errorList;


    public static Result error() {
        return error("500", "(ERROR)异常");
    }

    public static Result error(String msg) {
        return error("500", msg);
    }
    
    public static Result error(List<String> errorList){
        return error("500",errorList);
    }

    public static Result error(String code, String msg) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static Result error(String code, List<String> errorList) {
        Result r = new Result();
        r.setCode(code);
        r.setErrorList(errorList);
        return r;
    }

    public static <T> Result error(T content) {
        Result r = new Result();
        r.setCode("500");
        r.setMsg("异常");
        r.setResult(content);
        return r;
    }

    public static <T> Result error(String code, String msg, T content) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setResult(content);
        return r;
    }

    public static <T> Result error(String code, String msg, T content,String redirectUrl) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setResult(content);
        r.setRedirectUrl(redirectUrl);
        return r;
    }

    public static <T> Result error(String code, String msg, String redirectUrl) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setRedirectUrl(redirectUrl);
        return r;
    }

    public static <T> Result ok(String msg, T content) {
        Result r = new Result();
        r.setCode("0");
        r.setMsg(msg);
        r.setResult(content);
        return r;
    }


    public static Result ok() {
        Result r = new Result();
        r.setCode("0");
        r.setMsg("成功");
        return r;
    }

    public static Result ok(String msg) {
        Result r = new Result();
        r.setCode("0");
        r.setMsg(msg);
        return r;
    }

    public static <T> Result ok(T result) {
        Result r = new Result();
        r.setCode("0");
        r.setMsg("成功");
        r.setResult(result);
        return r;
    }

    public static Result ok(String code, String msg) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
    public static<T> Result ok(String code, String msg,T content ) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setResult(content);
        return r;
    }

    public boolean isOk() {
        return "0".equals(this.getCode()) || "000000".equals(this.getCode()) || "0000".equals(this.getCode());
    }
}
