package com.ycwl.basic.integration.common.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CommonResponse<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> CommonResponse<T> success() {
        return new CommonResponse<>(200, "OK", null);
    }

    public static <T> CommonResponse<T> success(T data) {
        return new CommonResponse<>(200, "OK", data);
    }

    public static <T> CommonResponse<T> success(String message, T data) {
        return new CommonResponse<>(200, message, data);
    }

    public static <T> CommonResponse<T> error(Integer code, String message) {
        return new CommonResponse<>(code, message, null);
    }

    public static <T> CommonResponse<T> error(String message) {
        return new CommonResponse<>(5000, message, null);
    }

    public boolean isSuccess() {
        return code != null && code == 200;
    }
}