package com.wzj.soopin.im.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.im.domain.SysMessage;
import com.wzj.soopin.im.service.ISysMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import com.wzj.soopin.im.domain.vo.SysMessageVo;
import com.wzj.soopin.im.service.ISysMessageTemplateService;
import org.dromara.system.service.ISysUserService;
import com.wzj.soopin.im.service.impl.SystemMessageUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static org.dromara.common.satoken.utils.LoginHelper.getUserId;


@Tag(name = "用户消息")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/im/message/task")
public class IMMessageUserController extends BaseController {

    private final ISysMessageService messageService;
    private final ISysUserService userService;
    private final ISysMessageTemplateService templateService;

    private final SystemMessageUserService systemMessageTaskService;




//    @SaCheckPermission("system:message:list")
    @Operation(summary = "查询未读消息列表")
    @PostMapping("/unread")
    public R<Page<SysMessageVo>> unreadList(@RequestBody Page<SysMessage> page) {
        Page<SysMessageVo> unreadPage = messageService.selectUnreadMessagesPage(getUserId(), page);
        return R.ok(unreadPage);
    }

//    @SaCheckPermission("system:message:list")
    @Operation(summary = "查询已读消息列表")
    @PostMapping("/read")
    public R<Page<SysMessageVo>> readList(@RequestBody Page<SysMessage> page) {
        Page<SysMessageVo> readPage = messageService.selectReadMessagesPage(getUserId(), page);
        return R.ok(readPage);
    }


//    @SaCheckPermission("system:message:mark")
    @Operation(summary = "标记消息为已读")
    @Log(title = "消息管理", businessType = BusinessType.UPDATE)
    @PutMapping("/mark/{id}")
    public R<Void> markAsRead(@NotNull(message = "消息ID不能为空") @PathVariable Long id) {
        return toAjax(messageService.markAsRead(id, getUserId()));
    }


    @Operation(summary = "删除消息")
//    @SaCheckPermission("system:message:remove")
    @Log(title = "消息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "消息ID不能为空") @PathVariable Long[] ids) {
        return toAjax(messageService.deleteMessageByIds(ids));
    }

}
