package com.xy.xyaicpzs.common.response;

import lombok.Data;

/**
 * API响应对象
 */
@Data
public  class ApiResponse<T> {
    private Integer code;
    private boolean success;
    private String message;
    private T data;

    public static <T> ApiResponse<T> success(T data) {
        ApiResponse<T> response = new ApiResponse<>();
        response.code = 0;
        response.success = true;
        response.message = "操作成功";
        response.data = data;
        return response;
    }

    public static <T> ApiResponse<T> error(String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.code = 1;
        response.success = false;
        response.message = message;
        return response;
    }

    public static <T> ApiResponse<T> error(Integer code, String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.code = code;
        response.success = false;
        response.message = message;
        return response;
    }

}