package com.fs.common.core.domain;


import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Result<T> {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 是否成功
     */
    private Boolean success;

    /**
     * 消息描述
     */
    private String message;

    /**
     * 数据，可以是任何类型的VO
     */
    private T data;

    public Result() {
    }

    public Result(Boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public Result(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
        this.code = code;
    }


    public static <T> Result<T> success(T data) {
        return new Result<>(true, 200, ResponseCode.SUCCESS.name(), data);
    }

    public static <T> Result<T> error(String errorMsg) {
        return new Result<>(false, 500, errorMsg, null);
    }
}
