package com.sckw.core.web.response;


import lombok.Data;

import java.io.Serializable;

/**
 * @Author: donglang
 * @CreateTime: 2025-10-09
 * @Description: 返回模型
 * @Version: 1.0
 */

@Data
public class BaseIotResult<T> implements Serializable {


    /**
     * 处理是否成功
     */
    protected boolean success = true;

    /**
     * 错误码
     */
    protected String code;

    /**
     * 错误信息
     */
    protected String message;

    /**
     * 业务数据
     */
    protected T data;

    /**
     * 构建成功结果，包含具体信息
     */
    public static <T> BaseIotResult<T> success(T data) {
        BaseIotResult<T> result = new BaseIotResult<>();
        result.setSuccess(true);
        result.setCode("0");
        result.setData(data);
        return result;
    }

    /**
     * 构建成功结果，无返回具体信息
     */
    public static <T> BaseIotResult<T> success() {
        return success(null);
    }

    /**
     * 构建失败结果，返回错误信息
     */
    public static <T> BaseIotResult<T> error(String code, String message) {
        BaseIotResult<T> result = new BaseIotResult<>();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

}
