package com.example.controller;

import com.example.common.Result;
import com.example.entity.ChatMessage;
import com.example.service.ChatMessageService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 聊天消息控制器
 */
@RestController
@RequestMapping("/chat")
public class ChatMessageController {
    
    @Resource
    private ChatMessageService chatMessageService;
    
    /**
     * 发送消息
     */
    @PostMapping("/send")
    public Result send(@RequestBody ChatMessage chatMessage) {
        ChatMessage message = chatMessageService.sendMessage(chatMessage);
        return Result.success(message);
    }
    
    /**
     * 获取聊天历史记录
     */
    @GetMapping("/history")
    public Result getChatHistory(@RequestParam Integer contactId, @RequestParam String contactType) {
        List<ChatMessage> messages = chatMessageService.getChatHistory(contactId, contactType);
        return Result.success(messages);
    }
    
    /**
     * 获取聊天联系人列表
     */
    @GetMapping("/contacts")
    public Result getContactList() {
        List<Map<String, Object>> contacts = chatMessageService.getContactList();
        return Result.success(contacts);
    }
} 