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

import com.red.circle.console.app.dto.clienobject.game.GameUserLotteryRecordCO;
import com.red.circle.console.app.dto.clienobject.game.GameUserShardsExchangeRecordCO;
import com.red.circle.console.app.service.app.game.GameEggBackService;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.inner.model.cmd.game.GameEggConfigCmd;
import com.red.circle.other.inner.model.cmd.game.GameEggQryCmd;
import com.red.circle.other.inner.model.dto.game.GameEggStockConfigDTO;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 砸金蛋记录 前端控制器.
 *
 * @author pengshigang
 * @since 2021-11-12
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/game/egg")
public class GameEggRestController extends BaseController {

  private final GameEggBackService gameEggBackService;

  /**
   * 查询配置.
   */
  @GetMapping("/config")
  public List<GameEggStockConfigDTO> config(String sysOrigin) {
    return gameEggBackService.listConfig(sysOrigin);
  }

  /**
   * 编辑配置.
   */
  @OpsOperationReqLog(value = "编辑配置-egg", ignoreRequestParam = true)
  @PostMapping("/config")
  public void config(@RequestBody @Validated GameEggConfigCmd param) {
    gameEggBackService.updateConfig(param);
  }

  /**
   * 重置库存消耗.
   */
  @OpsOperationReqLog(value = "重置库存消耗-eg", ignoreRequestParam = true)
  @GetMapping("/config/reset-consume-stock")
  public void reset(Long id) {
    gameEggBackService.updateConsumeStockQuantityZero(id);
  }

  /**
   * 奖金池.
   */
  @GetMapping("/config/prize-pool")
  public String prizePool(String sysOrigin) {
    return gameEggBackService.getPrizePool(sysOrigin);
  }

  /**
   * 抽取概率-获取.
   */
  @GetMapping("/config/extract-pool")
  public String getExtractRatio(String sysOrigin) {
    return gameEggBackService.getExtractRatio(sysOrigin);
  }

  /**
   * 重置库存消耗.
   */
  @OpsOperationReqLog(value = "重置库存消耗-eg")
  @GetMapping("/config/set-extract-pool")
  public void setExtractRatio(String sysOrigin, String ratio) {
    gameEggBackService.setExtractRatio(sysOrigin, ratio);
  }

  /**
   * 抽奖记录
   */
  @GetMapping("/lottery/record/page")
  public PageResult<GameUserLotteryRecordCO> pageLotteryRecord(GameEggQryCmd query) {
    return gameEggBackService.pageGameUserLotteryRecord(query);
  }

  /**
   * 兑换记录
   */
  @GetMapping("/exchange/page")
  public PageResult<GameUserShardsExchangeRecordCO> pageExchangeRecord(
      GameEggQryCmd query) {
    return gameEggBackService.pageExchangeRecord(query);
  }
}
