package com.tongran.rocketmq.controller;

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

import java.util.List;

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

    /**
     * 查询Agent管理列表
     */
    @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管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmAgentManagementService.selectRmAgentManagementById(id));
    }

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

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

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

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