package com.red.circle.other.adapter.app;

import com.red.circle.other.app.dto.clientobject.RocketRewardCO;
import com.red.circle.other.app.dto.clientobject.RocketStatusCO;
import com.red.circle.other.app.dto.cmd.RocketRewardClaimCmd;
import com.red.circle.other.app.dto.cmd.RocketStatusQueryCmd;
import com.red.circle.other.app.service.RocketService;
import com.red.circle.other.domain.gateway.RocketConfigGateway;
import com.red.circle.other.domain.rocket.RocketConfig;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 火箭REST控制器
 *
 * @author system
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/api/rocket")
@RequiredArgsConstructor
public class RocketRestController {

    private final RocketService rocketService;
    private final RocketConfigGateway rocketConfigGateway;

    /**
     * 查询火箭状态
     */
    @GetMapping("/status")
    public RocketStatusCO queryStatus(@Valid RocketStatusQueryCmd cmd) {
        return rocketService.queryStatus(cmd);
    }

    /**
     * 查询所有启用的火箭配置
     */
    @GetMapping("/config/enabled")
    public List<RocketConfig> queryEnabledConfigs() {
        return rocketConfigGateway.findAllEnabled();
    }

    /**
     * 领取奖励
     */
    @PostMapping("/claim")
    public RocketRewardCO claimReward(@Valid @RequestBody RocketRewardClaimCmd cmd) {
        cmd.setReceive(true);
        return rocketService.claimReward(cmd);
    }
}
