package com.dd.admin.business.chat.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.dd.admin.common.model.UpdateGroup;
import com.dd.admin.common.model.result.ResultBean;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotBlank;
import com.dd.admin.business.chat.entity.Chat;
import com.dd.admin.business.chat.domain.ChatVo;
import com.dd.admin.business.chat.domain.ChatDto;
import com.dd.admin.business.chat.service.ChatService;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 727869402@qq.com
 * @since 2024-12-28
 */
@Api(tags = "")
@RestController
public class ChatController {

    @Autowired
    ChatService chatService;

    @ApiOperation(value = "-分页列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("/admin/chat/page")
    public ResultBean<IPage<ChatVo>> page(ChatDto chatDto) {
        IPage<ChatVo> pageInfo = chatService.selectChatPage(chatDto);
        return ResultBean.success(pageInfo);
    }

    @ApiOperation(value = "-列表")
    @ApiOperationSupport(order = 2)
    @GetMapping("/admin/chat/list")
    public ResultBean<List<ChatVo>> list(ChatDto chatDto) {
        List<ChatVo> list = chatService.selectChatDetail(chatDto);
        return ResultBean.success(list);
    }

    @ApiOperation(value = "-添加")
    @ApiOperationSupport(order = 3)
    @PostMapping("/admin/chat/add")
    public ResultBean<Chat> add(@RequestBody @Validated ChatDto chatDto) {
        Chat chat = BeanUtil.copyProperties(chatDto, Chat.class);
        chatService.save(chat);
        return ResultBean.success(chat);
    }

    @ApiOperation(value = "-查询")
    @ApiOperationSupport(order = 4)
    @GetMapping("/admin/chat/{chatId}")
    public ResultBean<ChatVo> get(@PathVariable @NotBlank String chatId) {
        Chat chat = chatService.getById(chatId);
        ChatVo chatVo = BeanUtil.copyProperties(chat,ChatVo.class);
        return ResultBean.success(chatVo);
    }

    @ApiOperation(value = "-修改")
    @ApiOperationSupport(order = 5)
    @PostMapping("/admin/chat/update")
    public ResultBean<Chat> update(@RequestBody @Validated(UpdateGroup.class) ChatDto chatDto) {
        Chat chat = BeanUtil.copyProperties(chatDto, Chat.class);
        chatService.updateById(chat);
        return ResultBean.success(chat);
    }

    @ApiOperation(value = "-删除")
    @ApiOperationSupport(order = 6)
    @GetMapping("/admin/chat/delete/{chatId}")
    public ResultBean<Chat> delete(@PathVariable @NotBlank String chatId) {
        Boolean b = chatService.removeById(chatId);
        return ResultBean.success(b);
    }
}
