package org.qinan.safetyeval.client.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 通用单条数据响应体
 * <p>
 * 与 GBS SingleResponse 格式保持一致，当 GBS 依赖可用时可平滑切换。
 * </p>
 *
 * @author safety-eval
 */
@Data
public class SingleResponse<T> {

    @ApiModelProperty(value = "是否成功")
    private boolean success;

    @ApiModelProperty(value = "响应码")
    private String code;

    @ApiModelProperty(value = "响应消息")
    private String message;

    @ApiModelProperty(value = "错误响应消息")
    private String errMessage;

    @ApiModelProperty(value = "响应数据")
    private T data;

    public static <T> SingleResponse<T> success(T data) {
        SingleResponse<T> response = new SingleResponse<>();
        response.setSuccess(true);
        response.setCode("0");
        response.setData(data);
        return response;
    }

    public static SingleResponse<Void> success() {
        SingleResponse<Void> response = new SingleResponse<>();
        response.setSuccess(true);
        response.setCode("0");
        return response;
    }

    public static <T> SingleResponse<T> error(String code, String message) {
        SingleResponse<T> response = new SingleResponse<>();
        response.setSuccess(false);
        response.setCode(code);
        response.setMessage(message);
        response.setErrMessage(message);
        return response;
    }
}
