package com.mcwl.communityCenter.service.impl;

import com.mcwl.communityCenter.domain.ChatMessage;
import com.mcwl.communityCenter.service.HumanService;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class HumanServiceImpl implements HumanService {

    // 已上线的客服，key为用户ID，value为WebSocketSession
    private static final Map<String, WebSocketSession> activeSessions = new ConcurrentHashMap<>();

    @Override
    public void transferToHuman(String userId, WebSocketSession session) {
        activeSessions.put(userId, session);
        // 这里可以添加通知客服人员的逻辑
    }

    @Override
    public void handleHumanMessage(String userId, String message) throws IOException {
        // 应实现消息队列或持久化存储
        // 先返回固定响应
        WebSocketSession session = activeSessions.get(userId);
        if (session != null && session.isOpen()) {
            session.sendMessage(new TextMessage("[客服] 您好，当前为人工服务模式"));
        }
    }

    @Override
    public void transferToAgent(String sessionId, List<ChatMessage> history) {


    }
}
