package com.ruoyi.rocketmq.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rocketmq.domain.RmAgentManagement;
import com.ruoyi.rocketmq.service.IRmAgentManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Agent管理Controller
 * 
 * @author gyt
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/agentManagement")
public class RmAgentManagementController extends BaseController
{
    @Autowired
    private IRmAgentManagementService rmAgentManagementService;

    /**
     * 查询Agent管理列表
     */
    @RequiresPermissions("rocketmq:management:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RmAgentManagement rmAgentManagement)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmAgentManagement.getPageNum());
        pageDomain.setPageSize(rmAgentManagement.getPageSize());
        startPage(pageDomain);
        List<RmAgentManagement> list = rmAgentManagementService.selectRmAgentManagementList(rmAgentManagement);
        return getDataTable(list);
    }

    /**
     * 获取Agent管理详细信息
     */
    @RequiresPermissions("rocketmq:management:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmAgentManagementService.selectRmAgentManagementById(id));
    }

    /**
     * 新增Agent管理
     */
    @RequiresPermissions("rocketmq:management:add")
    @Log(title = "Agent管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmAgentManagement rmAgentManagement)
    {
        return toAjax(rmAgentManagementService.addRmAgentManagement(rmAgentManagement));
    }

    /**
     * 修改Agent管理
     */
    @RequiresPermissions("rocketmq:management:edit")
    @Log(title = "Agent管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmAgentManagement rmAgentManagement)
    {
        return toAjax(rmAgentManagementService.updateRmAgentManagement(rmAgentManagement));
    }

    /**
     * 手动立即更新
     * @param rmAgentManagement
     * @return
     */
    @RequiresPermissions("rocketmq:management:edit")
    @PostMapping("/updateAgentNow")
    public AjaxResult updateAgentNow(@RequestBody RmAgentManagement rmAgentManagement){
        rmAgentManagementService.updateAgentNow(rmAgentManagement);
        return success();
    }

    /**
     * 配置更新策略
     */
    @RequiresPermissions("rocketmq:management:add")
    @Log(title = "Agent管理", businessType = BusinessType.INSERT)
    @PostMapping("/addUpdatePolicy")
    public AjaxResult addUpdatePolicy(@RequestBody RmAgentManagement rmAgentManagement)
    {
        return toAjax(rmAgentManagementService.addUpdatePolicy(rmAgentManagement));
    }
}
