package cn.qinys.platform.base.response;


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

import java.io.Serializable;

/**
 * Description:
 *
 * @author tanlie
 * Date: 2024/1/9 8:32
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 4822942452184119123L;
    private int code;
    private String msg;
    private T data;

    public Result(ResultCodeEnum rCode) {
        this.code = rCode.getCode();
        this.msg = rCode.getDesc();
    }

    public Result(String msg) {
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.msg = msg;
        this.data = (T) msg;
    }

    public Result(T data) {
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.msg = ResultCodeEnum.SUCCESS.getDesc();
        this.data = data;
    }

    public Result(String msg, T data) {
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.msg = msg;
        this.data = data;
    }

    public Result(ResultCodeEnum rCode, T data) {
        this.code = rCode.getCode();
        this.msg = rCode.getDesc();
        this.data = data;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result setCodeEnum(ResultCodeEnum rCode) {
        this.code = rCode.getCode();
        return this;
    }

}