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

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.dto.clientobject.SpinsTaskCO;
import com.red.circle.other.app.dto.clientobject.SpinsTaskRewardCO;
import com.red.circle.other.app.dto.cmd.SpinsTaskReceiveRewardCmd;
import com.red.circle.other.app.service.SpinsTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Spins任务接口
 *
 * @author system
 * @date 2025-01-21
 */
@Slf4j
@RestController
@RequestMapping("/spins/task")
@RequiredArgsConstructor
public class SpinsTaskRestController {

    private final SpinsTaskService spinsTaskService;

    /**
     * 获取用户任务列表
     *
     * @param cmd 用户ID
     * @return 任务列表
     */
    @GetMapping("/list")
    public List<SpinsTaskCO> getTaskList(AppExtCommand cmd, @RequestParam(required = false) Long activityId) {
        Long userId = cmd.getReqUserId();
        log.info("获取用户任务列表, userId={}", userId);
        if (activityId == null) {
            activityId = 2006671533988298666L;
        }
        List<SpinsTaskCO> taskList = spinsTaskService.getUserTaskList(userId, activityId);
        return taskList;
    }

    /**
     * 领取任务奖励
     *
     * @param cmd 领取奖励命令
     * @return 奖励信息
     */
    @PostMapping("/receive/reward")
    public SpinsTaskRewardCO receiveReward(@Validated @RequestBody SpinsTaskReceiveRewardCmd cmd) {
        return spinsTaskService.receiveTaskReward(cmd);
    }
}
