package com.kxs.system.biz.controller.kxsapp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kxs.common.core.util.R;
import com.kxs.common.security.annotation.Inner;
import com.kxs.system.api.model.KxsUserMsg;
import com.kxs.system.api.vo.kxsapp.NotReadCountVo;
import com.kxs.system.api.vo.kxsapp.userMsg.UserMsgPageVO;
import com.kxs.system.biz.service.KxsUserMsgService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 消息(UserMsg)控制层
 *
 * @author 系统
 * @since 2023-12-15 12:16:33
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("userMsg")
public class UserMsgController {

    /**
     * 服务对象
     */
    private final KxsUserMsgService kxsUserMsgService;



    /**
     * 个人消息-消息列表
     *
     * @param page 分页对象
     * @return 个人消息-消息列表
     */
    @GetMapping("/page")
    public R page(@ParameterObject Page<UserMsgPageVO> page) {
        return R.ok(kxsUserMsgService.getByPage(page));
    }


    /**
     * 个人消息-消息详情
     *
     * @param id 主键ID
     * @return 个人消息-消息详情
     */
    @GetMapping("/getById")
    public R getById(@RequestParam("id") Integer id) {
        return R.ok(kxsUserMsgService.getByData(id));
    }

    /**
     * 消息未读数
     *
     * @return 消息未读数
     */
    @GetMapping("/notread")
    public R<NotReadCountVo> notread() {
        return R.ok(kxsUserMsgService.notreads());
    }

    /**
     * 个人消息-全部已读
     *
     * @return 个人消息-全部已读
     */
    @PostMapping("/readAll")
    public R readAll() {
        kxsUserMsgService.readAll();
        return R.ok();
    }

    @Inner
    @PostMapping("/save")
    public R save(@Valid @RequestBody KxsUserMsg userMsg){

        return R.ok(kxsUserMsgService.saveMsg(userMsg));
    }





}

