package com.ag.secp.platform.jwt;

import lombok.Data;
import lombok.experimental.Accessors;

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

/**
 * Description: 统一返回结果的类
 * Author: songwp
 * Version: 1.0
 * Create Date: 2021/9/3
 */

@Data
@Accessors(chain = true)//可以进行链式操作
public class R {

    private int respCode;

    private String respMsg;

    private Map<String,Object> data = new HashMap<>();

    /**
     * Description：私有构造方法
     * @param
     * @return: com.ag.secp.mobile.common.R
     * @Author songwp
     * Create Date  2021/9/3
     */
    private R(){}

    /**
     * Description：请求成功静态方法
     * @param
     * @return: com.ag.secp.mobile.common.R
     * @Author songwp
     * Create Date  2021/9/3
     */
    public static R success() {
        R r = new R();
        r.setRespCode(ResultCode.SUCCESS);
        r.setRespMsg(ResultCode.SUCCESS_MSG);
        return r;
    }

    /**
     * Description：请求失败静态方法
     * @param
     * @return: com.ag.secp.mobile.common.R
     * @Author songwp
     * Create Date  2021/9/3
     */
    public static R failed(String failedMsg) {
        R r = new R();
        r.setRespCode(ResultCode.FAILED);
        r.setRespMsg(failedMsg);
        return r;
    }

    /**
     * Description：TOKEN验证失败
     * @param
     * @return: com.ag.secp.mobile.common.R
     * @Author songwp
     * Create Date  2021/9/3
     */
    public static R failedToken() {
        R r = new R();
        r.setRespCode(ResultCode.LOGIN_REQUIRED);
        r.setRespMsg(ResultCode.TOKEN_VERIFY_ERROR);
        return r;
    }

    public R setRData(String key,Object value) {
        this.data.put(key,value);
        return this;
    }

    public R setRData(Map<String,Object> map) {
        this.setData(map);
        return this;
    }


}
