package com.ruoyi.web.controller.jarvis;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jarvis.domain.WeComInboundTrace;
import com.ruoyi.jarvis.domain.dto.WeComTestDataCleanRequest;
import com.ruoyi.jarvis.service.IWeComInboundTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企微 inbound 消息追踪查询
 */
@RestController
@RequestMapping("/jarvis/wecom/inboundTrace")
public class WeComInboundTraceController extends BaseController {

    @Autowired
    private IWeComInboundTraceService weComInboundTraceService;

    @PreAuthorize("@ss.hasPermi('jarvis:wecom:inboundTrace:list')")
    @GetMapping("/list")
    public TableDataInfo list(WeComInboundTrace query) {
        startPage();
        List<WeComInboundTrace> list = weComInboundTraceService.selectWeComInboundTraceList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('jarvis:wecom:inboundTrace:list')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(weComInboundTraceService.selectWeComInboundTraceById(id));
    }

    @PreAuthorize("@ss.hasPermi('jarvis:wecom:inboundTrace:remove')")
    @Log(title = "企微消息跟踪", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(weComInboundTraceService.deleteWeComInboundTraceByIds(ids));
    }

    /**
     * 清理联调/测试数据：追踪表 + 可选 Redis 企微会话与 adhoc 队列
     */
    @PreAuthorize("@ss.hasPermi('jarvis:wecom:inboundTrace:remove')")
    @Log(title = "企微消息测试数据清理", businessType = BusinessType.CLEAN)
    @PostMapping("/cleanTestData")
    public AjaxResult cleanTestData(@RequestBody(required = false) WeComTestDataCleanRequest body) {
        return success(weComInboundTraceService.cleanTestData(body));
    }
}
