package com.sckw.message.controller;

import com.sckw.core.model.page.PageRes;
import com.sckw.core.utils.BeanUtils;
import com.sckw.core.web.response.HttpResult;
import com.sckw.message.model.KwmMessage;
import com.sckw.message.model.dto.SelectMessagesDTO;
import com.sckw.message.model.vo.req.DeleteMessagesReqVO;
import com.sckw.message.model.vo.req.ReadMessagesReqVO;
import com.sckw.message.model.vo.req.SelectMessagesReqVO;
import com.sckw.message.model.vo.req.StatisticsMessagesReqVO;
import com.sckw.message.service.MessageService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @param
 * @desc: 消息相关接口
 * @author: yzc
 * @date: 2023-06-09 15:13
 * @return
 */
@RestController
@RequestMapping(value = "/kwmMessage")
@RequiredArgsConstructor
public class MessageController {

    private final MessageService messageService;

    /**
     * @param id
     * @return com.sckw.core.web.response.HttpResult
     * @desc: 获取消息详情
     * @author: yzc
     * @date: 2023-06-13 16:17
     */
    @GetMapping("/detail")
    public HttpResult detail(@RequestParam Long id) {
        KwmMessage message = messageService.detail(id);
        return HttpResult.ok("获取消息详情成功", message);
    }

    /**
     * @param params
     * @return com.sckw.core.web.response.HttpResult
     * @desc: 分页查询消息
     * @author: yzc
     * @date: 2023-06-09 15:12
     */
    @PostMapping(value = "/select", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult select(@RequestBody @Valid SelectMessagesReqVO params) {
        PageRes res = messageService.select(BeanUtils.copyProperties(params, SelectMessagesDTO.class));
        return HttpResult.ok("分页查询消息成功", res);
    }

    /**
     * @desc: 消息列表统计查询
     * @author: yzc
     * @date: 2023-08-22 10:57
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/statistic", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult statistic(@RequestBody @Valid StatisticsMessagesReqVO params) {
        return HttpResult.ok("消息列表统计查询成功", messageService.statistics(params));
    }

    /**
     * @param readMessagesReqVO
     * @return com.sckw.core.web.response.HttpResult
     * @desc: 消息已读
     * @author: yzc
     * @date: 2023-06-09 14:21
     */
    @PostMapping(value = "/read", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult read(@RequestBody @Valid ReadMessagesReqVO readMessagesReqVO) {
        messageService.read(readMessagesReqVO);
        return HttpResult.ok("读取消息成功");
    }

    /**
     * @param deleteMessagesReqVO
     * @return com.sckw.core.web.response.HttpResult
     * @desc: 删除消息
     * @author: yzc
     * @date: 2023-06-09 14:21
     */
    @PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult delete(@RequestBody @Valid DeleteMessagesReqVO deleteMessagesReqVO) {
        messageService.delete(deleteMessagesReqVO);
        return HttpResult.ok("删除消息成功");
    }

    /**
     * @desc: 用户消息中心
     * @author: yzc
     * @date: 2023-09-07 14:57
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GetMapping("/userMsgCenter")
    public HttpResult userMsgCenter() {
        return HttpResult.ok("获取用户消息中心成功", messageService.userMsgCenter());
    }
}
