package cn.teammodel.ai;

import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@UtilityClass
@Slf4j
public class SseHelper {
    /**
    * 断开 server 与 client 的 sse 连接
    */
    public void complete(SseEmitter sseEmitter) {
        try {
            sseEmitter.complete();
        } catch (Exception e) {
        }
    }

    /**
    * 向 client 发送消息
    */
    public void send(SseEmitter sseEmitter, Object data) {
        try {
            sseEmitter.send(data);
        } catch (Exception e) {
            log.error("sseEmitter send error", e);
        }
    }
}
