package com.m2pool.chat.controller;

import com.m2pool.chat.dto.ChatRoomDto;
import com.m2pool.chat.service.ChatRoomService;
import com.m2pool.chat.vo.CharRoomVo;
import com.m2pool.chat.vo.RoomPageVo;
import com.m2pool.chat.vo.RoomVo;
import com.m2pool.common.core.Result.R;
import com.m2pool.common.core.web.page.TableDataInfo;
import com.m2pool.common.security.annotation.RequiresLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Api(tags = "聊天室相关接口")
@RestController
@RequestMapping("/rooms")
public class ChatRoomController {

    @Autowired
    private ChatRoomService chatRoomService;


    @PostMapping("/find/room/list")
    @ApiOperation(value = "客服端：查询客服人员的聊天室列表")
    @RequiresLogin
    public TableDataInfo<ChatRoomDto> findRoomList(@RequestBody(required = false) RoomPageVo roomPageVo) {
        // 如果请求体为空，初始化一个默认的 RoomPageVo 对象
        if (roomPageVo == null) {
            roomPageVo = new RoomPageVo();
            roomPageVo.setSendDateTime(LocalDateTime.now());
        }
        return chatRoomService.findRoomList(roomPageVo);
    }

    @PostMapping("/find/room/by/userid")
    @ApiOperation(value = "客户端：根据当前用户邮箱查询聊天室")
    public R<ChatRoomDto> findRoomByUserid(@RequestBody RoomVo roomVo) {
        return chatRoomService.findRoomByUserid(roomVo);
    }


    @PostMapping("/update/room")
    @ApiOperation(value = "修改聊天室重要标记")
    @RequiresLogin
    public R<String> updateRoom(@RequestBody CharRoomVo charRoomVo) {
        return chatRoomService.updateRoom(charRoomVo);
    }
}
