package com.ruoyi.api.controller.user;

import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.validate.RegGroup;
import com.ruoyi.usernotice.domain.bo.UserNoticeBo;
import com.ruoyi.usernotice.domain.vo.UserNoticeVo;
import com.ruoyi.usernotice.service.IUserNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * C端用户通知Controller
 *
 * @author ruoyi
 * @date 2025-04-21
 */
@Validated
@Api(value = "C端用户通知控制器", tags = {"C端用户通知管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/userNotice")
public class ApiUserNoticeController extends AbstractApiController {

    private final IUserNoticeService iUserNoticeService;

    /**
     * 分页查询C端用户通知列表
     */
    @ApiOperation("查询C端用户通知列表")
    @GetMapping("/page")
    public TableDataInfo<UserNoticeVo> page(@Validated(QueryGroup.class) UserNoticeBo bo, PageQuery pageQuery) {
        bo.setUserId(getUserId());
        return iUserNoticeService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询C端用户未读消息数
     */
    @ApiOperation("查询C端用户未读消息数")
    @GetMapping("/count")
    public R count() {
        return R.ok(iUserNoticeService.queryUserCount(getUserId(), false));
    }

    /**
     * 设置已读
     */
    @ApiOperation("设置已读")
    @RepeatSubmit()
    @PostMapping("/setStatus")
    public R<Void> setStatus(@Validated(RegGroup.class) @RequestBody UserNoticeBo bo) {
        getUserId();
        iUserNoticeService.setStatus(bo.getId());
        return R.ok();
    }

    /**
     * 设置全部已读
     */
    @ApiOperation("设置全部已读")
    @RepeatSubmit()
    @PostMapping("/setAllStatus")
    public R<Void> setAllStatus() {
        iUserNoticeService.setAllStatus(getUserId());
        return R.ok();
    }

}
