package com.education.business.message.mq;

import com.education.business.message.param.LoginDeviceMessage;
import com.education.common.enums.SocketMessageTypeEnum;
import com.education.common.utils.Ip2regionUtil;
import com.education.model.dto.SocketMessageCommand;
import org.springframework.stereotype.Component;

/**
 * @author zjt
 * @version 1.0.7
 * @Description
 * @createTime 2025/2/25 10:11
 */
@Component
public class WebSocketLoginDeviceMessageListener extends WenSocketMessageListener<LoginDeviceMessage> {

    @Override
    SocketMessageCommand getSocketMessageCommand(LoginDeviceMessage webSocketMessage) {
        String ip = webSocketMessage.getIp();
        String address = Ip2regionUtil.getIpProvinceAndCity(ip);
        String content = "您的账号已在" + address + "登录，" +
                "5秒后将自动下线，如非本人操作请重新登录并及时修改密码";
        SocketMessageCommand socketMessageCommand = new SocketMessageCommand();
        socketMessageCommand.setMsgContent(content);
        socketMessageCommand.setMessageType(getSocketMessageTypeEnum().getCode());
        return socketMessageCommand;
    }

    @Override
    SocketMessageTypeEnum getSocketMessageTypeEnum() {
        return SocketMessageTypeEnum.REJECT_SESSION;
    }
}
