package com.seer.teach.netty.im.handler.im.singlechat;

import com.seer.teach.iot.api.UserDeviceServiceApi;
import com.seer.teach.netty.common.annotation.ImMessageContentType;
import com.seer.teach.netty.common.proto.MessageProtobuf;
import com.seer.teach.netty.im.handler.im.ImMessageContentHandler;
import com.seer.teach.teacher.api.SseServiceApi;
import io.netty.channel.ChannelHandlerContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author 18501
 */
@Service
@Slf4j
@Component
@ImMessageContentType(144)
@RequiredArgsConstructor
public class ExitSmartReadingOrTreasureChestsHandlerImpl implements ImMessageContentHandler {

    private final SseServiceApi sseServiceApi;

    private final UserDeviceServiceApi userDeviceServiceApi;

    @Override
    public void handle(ChannelHandlerContext ctx, MessageProtobuf.Msg msg) {
        String device = msg.getHead().getDevice();
        Integer userId = userDeviceServiceApi.getUserIdByDevice(device);
        sseServiceApi.closeReadSse(userId);
    }

}
