package com.red.circle.console.adapter.admin;

import com.red.circle.console.app.command.rocket.RocketConfigQueryExe;
import com.red.circle.console.app.command.rocket.RocketConfigUpdateExe;
import com.red.circle.console.app.command.rocket.RocketStatisticsQueryExe;
import com.red.circle.console.app.dto.clienobject.RocketConfigCO;
import com.red.circle.console.app.dto.clienobject.RocketStatisticsCO;
import com.red.circle.console.app.dto.cmd.RocketConfigQueryCmd;
import com.red.circle.console.app.dto.cmd.RocketConfigUpdateCmd;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 火箭配置管理控制器
 *
 * @author system
 * @date 2025-01-15
 */
@Slf4j
@RestController
@RequestMapping("/admin/rocket/config")
@RequiredArgsConstructor
public class RocketConfigRestController {
    
    private final RocketConfigUpdateExe  rocketConfigUpdateExe;
    private final RocketStatisticsQueryExe rocketStatisticsQueryExe;
    private final RocketConfigQueryExe rocketConfigQueryExe;
    
    /**
     * 查询所有火箭配置
     */
    @GetMapping("/list")
    public List<RocketConfigCO> queryAll(RocketConfigQueryCmd cmd) {
        return rocketConfigQueryExe.queryAll(cmd);
    }
    
    /**
     * 根据ID查询配置
     */
    @GetMapping("/detail")
    public RocketConfigCO queryById(@RequestParam("id") Long id) {
        return rocketConfigQueryExe.queryById(id);
    }
    
    /**
     * 更新配置
     */
    @PostMapping("/update")
    public void update(@Valid @RequestBody RocketConfigUpdateCmd cmd) {
        rocketConfigUpdateExe.execute(cmd);
    }
    
    /**
     * 启用/禁用配置
     */
    @PostMapping("/updateStatus")
    public void updateStatus(@RequestParam("id") Long id, 
                              @RequestParam("status") Integer status) {
        rocketConfigUpdateExe.updateStatus(id, status);
    }
    
    /**
     * 查询统计数据
     */
    @GetMapping("/statistics")
    public RocketStatisticsCO queryStatistics() {
        return rocketStatisticsQueryExe.execute();
    }
}
