package com.wms_main.model.dto.response.wms;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.wms_main.constant.enums.wms.WmsApiResponseCodeEnums;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WmsApiResponse<T> extends BaseWmsApiResponse {
    /**
     * 返回数据
     */
    @JsonProperty("data")
    private T data;

    /**
     * 返回成功---无参
     * @return BaseWmsApiResponse
     */
    public static <T> WmsApiResponse<T> success(T data) {
        return success(WmsApiResponseCodeEnums.SUCCESS.getMessage(), data);
    }

    /**
     * 返回成功
     * @param message 自定义响应信息
     * @return BaseWmsApiResponse
     */
    public static <T> WmsApiResponse<T> success(String message, T data) {
        return instanceOf(WmsApiResponseCodeEnums.SUCCESS.getCode(), message, data);
    }

    /**
     * 返回错误---无参
     * @return BaseWmsApiResponse
     */
    public static <T> WmsApiResponse<T> error(T data) {
        return error(WmsApiResponseCodeEnums.ERROR.getMessage(), data);
    }

    /**
     * 返回错误
     * @param message 自定义响应信息
     * @return BaseWmsApiResponse
     */
    public static <T> WmsApiResponse<T> error(String message, T data) {
        return instanceOf(WmsApiResponseCodeEnums.ERROR.getCode(), message, data);
    }

    /**
     * 返回自定义
     * @param code 状态码
     * @param message 自定义响应信息
     * @return WmsApiResponse 响应实例
     */
    public static <T> WmsApiResponse<T> instanceOf(Integer code, String message, T data) {
        WmsApiResponse<T> wmsApiResponse = new WmsApiResponse<>();
        wmsApiResponse.setCode(code);
        wmsApiResponse.setMessage(message);
        wmsApiResponse.setData(data);
        return wmsApiResponse;
    }
}
