package com.red.circle.console.adapter.app.activity;

import com.red.circle.console.app.service.app.activity.LotteryActivityBackService;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.inner.model.cmd.activity.LotteryActivityQryCmd;
import com.red.circle.other.inner.model.cmd.activity.LotteryActivitySaveCmd;
import com.red.circle.other.inner.model.cmd.activity.LotteryPrizeSaveCmd;
import com.red.circle.other.inner.model.cmd.activity.LotteryRecordQryCmd;
import com.red.circle.other.inner.model.cmd.activity.LotteryTicketGrantCmd;
import com.red.circle.other.inner.model.dto.activity.LotteryActivityDTO;
import com.red.circle.other.inner.model.dto.activity.LotteryPrizeDTO;
import com.red.circle.other.inner.model.dto.activity.LotteryRecordDTO;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 抽奖活动管理.
 *
 * @author system on 2025-10-18
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/activity/lottery")
public class LotteryActivityBackRestController extends BaseController {

  private final LotteryActivityBackService lotteryActivityBackService;

  /**
   * 创建活动.
   */
  @PostMapping("/create")
  public void createActivity(@RequestBody @Validated LotteryActivitySaveCmd cmd) {
    lotteryActivityBackService.createActivity(cmd);
  }

  /**
   * 更新活动.
   */
  @PutMapping("/update")
  public void updateActivity(@RequestBody LotteryActivitySaveCmd cmd) {
    lotteryActivityBackService.updateActivity(cmd);
  }

  /**
   * 活动列表.
   */
  @GetMapping("/list")
  public PageResult<LotteryActivityDTO> listActivities(LotteryActivityQryCmd cmd) {
    return lotteryActivityBackService.listActivities(cmd);
  }

  /**
   * 活动详情.
   */
  @GetMapping("/detail/{id}")
  public LotteryActivityDTO getActivity(@PathVariable Long id) {
    return lotteryActivityBackService.getActivity(id);
  }

  /**
   * 更新活动状态.
   */
  @PutMapping("/status/{id}")
  public void updateActivityStatus(@PathVariable Long id, @RequestParam Integer status) {
    lotteryActivityBackService.updateActivityStatus(id, status);
  }

  /**
   * 配置奖品.
   */
  @PostMapping("/prize/save")
  public void savePrize(@RequestBody @Validated LotteryPrizeSaveCmd cmd) {
    lotteryActivityBackService.savePrize(cmd);
  }

  /**
   * 奖品列表.
   */
  @GetMapping("/prize/list/{activityId}")
  public List<LotteryPrizeDTO> listPrizes(@PathVariable Long activityId) {
    return lotteryActivityBackService.listPrizes(activityId);
  }

  /**
   * 删除奖品.
   */
  @DeleteMapping("/prize/delete/{id}")
  public void deletePrize(@PathVariable Long id) {
    lotteryActivityBackService.deletePrize(id);
  }

  /**
   * 中奖记录列表.
   */
  @GetMapping("/record/list")
  public PageResult<LotteryRecordDTO> listRecords(LotteryRecordQryCmd cmd) {
    return lotteryActivityBackService.listRecords(cmd);
  }

  /**
   * 发放奖品.
   */
  @PostMapping("/record/deliver/{recordId}")
  public void deliverPrize(@PathVariable Long recordId) {
    lotteryActivityBackService.deliverPrize(recordId);
  }

  /**
   * 批量发放抽奖券.
   */
  @PostMapping("/ticket/grant")
  public void grantTickets(@RequestBody @Validated LotteryTicketGrantCmd cmd) {
    lotteryActivityBackService.grantTickets(cmd);
  }

}
