package com.example.system.model;

import com.example.system.constant.ResultCode;
import lombok.Data;

@Data
public class Result<T>{
    private ResultCode code;//状态码
    private String errorInfo;//异常信息
    T data;//成功信息

    public Integer getCode() {
        return code.getCode();
    }

    /**
     * 后端响应成功
     * @param data
     * @return
     * @param <T>
     */
    public static <T> Result<T> success(T data) {
        Result<T> ret = new Result<>();
        ret.code = ResultCode.SUCCESS;
        ret.data = data;
        return ret;
    }
    /**
     * 后端响应失败
     * @param error
     * @return
     */
    public static Result<String> fail(String error) {
        Result<String> ret = new Result<>();
        ret.code = ResultCode.FAIL;
        ret.data = error;
        return ret;
    }
    /**
     * 用户未登录
     * @return
     */
    public static Result<String> notLogin() {
        Result<String> ret = new Result<>();
        ret.code = ResultCode.NOT_LOGIN;
        ret.errorInfo = "请登录";
        return ret;
    }
}
