package com.sckw.core.web.response;

import com.sckw.core.web.constant.HttpStatus;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;


@Data
public class BaseResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = -7714239361191848765L;
    private int code = HttpStatus.SUCCESS_CODE;
	private String message = HttpStatus.SUCCESS_MESSAGE;
	private T data;

    /**
     * 成功响应 - 无数据
     */
    public static <T> BaseResult<T> success() {
        return success(null);
    }
    /**
     * 成功响应 - 有数据
     */
    public static <T> BaseResult<T> success(T data) {
        BaseResult<T> result = new BaseResult<>();
        result.setData(data);
        return result;
    }
    public static <T> BaseResult<T> success(T data,String message) {
        BaseResult<T> result = new BaseResult<>();
        result.setData(data);
        result.setMessage(message);
        return result;
    }

    /**
     * 失败响应 - 自定义消息
     */
    public static <T> BaseResult<T> failed(String message) {
        BaseResult<T> result = new BaseResult<>();
        result.setCode(500);
        result.setMessage(message);
        return result;
    }

    /**
     * 失败响应 - 自定义码值和消息
     */
    public static <T> BaseResult<T> failed(int code, String message) {
        BaseResult<T> result = new BaseResult<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }


    public boolean isSuccess() {
        return code == HttpStatus.SUCCESS_CODE;
    }
}
