package com.cool.store.response.bigdata;

import com.cool.store.constants.CommonConstants;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.enums.ResponseCodeEnum;
import lombok.Data;
import org.slf4j.MDC;

/**
 * @Author suzhuhong
 * @Date 2025/4/1 10:49
 * @Version 1.0
 */
@Data
public class ApiResponse<T> {
    private String msg;
    private int code;
    private T data;
    private String stackTrace;
    private String requestId;


    public ApiResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.requestId = MDC.get(CommonConstants.REQUEST_ID);
    }

    public static<T> ApiResponse<T> success(T data) {
        return new ApiResponse(ResponseCodeEnum.SUCCESS.getCode(), "ok", data);
    }

    public static<T> ApiResponse<T> error(ErrorCodeEnum errorCodeEnum) {
        return new ApiResponse(errorCodeEnum.getCode(), errorCodeEnum.getMessage(), null);
    }
}
