package com.njcn.msgpush.module.push.controller.admin.retry;

import com.njcn.msgpush.framework.common.pojo.CommonResult;
import com.njcn.msgpush.framework.common.pojo.PageResult;
import com.njcn.msgpush.module.push.controller.admin.retry.vo.MessageRetryQueueReqVO;
import com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryQueueDO;
import com.njcn.msgpush.module.push.service.retry.MessageRetryQueueService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.njcn.msgpush.framework.common.pojo.CommonResult.success;

/**
 * @author caozehui
 * @data 2026-02-27
 */
@Tag(name = "管理后台 - 消息重试")
@Slf4j
@Validated
@RestController
@RequestMapping("/push/retry")
public class MessageRetryQueueController {

    @Autowired
    private MessageRetryQueueService messageRetryQueueService;

    @PostMapping("/page")
    @Operation(summary = "分页获得消息重试队列")
    @PreAuthorize("@ss.hasPermission('push:retry:page')")
    @Parameter(name = "reqVO", description = "分页查询参数", required = true)
    public CommonResult<PageResult<MessageRetryQueueDO>> getRetryPage(@Validated @RequestBody MessageRetryQueueReqVO reqVO) {
        PageResult<MessageRetryQueueDO> result = messageRetryQueueService.getPage(reqVO);
        return success(result);
    }

    @PostMapping("/manual")
    @Operation(summary = "批量手动重试消息")
    @PreAuthorize("@ss.hasPermission('push:retry:manual')")
    public CommonResult<Void> manualRetry(@RequestBody List<String> messageIds) {
        messageRetryQueueService.manualRetry(messageIds);
        return success(null);
    }
}
