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

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.wallet.app.dto.clientobject.CommodityRunningWaterCO;
import com.red.circle.wallet.app.dto.clientobject.DiamondConfigCO;
import com.red.circle.wallet.app.dto.cmd.DiamondExchangeGoldCmd;
import com.red.circle.wallet.app.dto.cmd.DiamondRunningWaterQueryCmd;
import com.red.circle.wallet.app.dto.cmd.UserBankExchangeGoldCmd;
import com.red.circle.wallet.app.service.DiamondService;
import com.red.circle.wallet.app.service.SalaryDiamondService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * yolo钻石相关
 *
 * @author pengliang on 2024/06/11
 * @eo.api-type http
 * @eo.groupName 钱包服务.钻石钱包
 * @eo.path /wallet/yolo/diamond
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/yolo/diamond", produces = MediaType.APPLICATION_JSON_VALUE)
public class YoloDiamondRestController extends BaseController {

  private final DiamondService diamondService;
  private final SalaryDiamondService salaryDiamondService;

  /**
   * 我的钻石余额.
   *
   * @eo.name 我的钻石余额.
   * @eo.url /balance
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/balance")
  public BigDecimal getBalance(AppExtCommand cmd) {
    return salaryDiamondService.getBalance(cmd);
  }

  /**
   * 获取最近一月流水.
   *
   * @eo.name 获取最近一月流水.
   * @eo.url /latest-one-months
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping(value = "/latest-one-months")
  public List<CommodityRunningWaterCO> latestOneMonthsFlow(DiamondRunningWaterQueryCmd cmd) {
    return salaryDiamondService.latestOneMonthsFlow(cmd);
  }

  /**
   * 获取兑换配置.
   *
   * @eo.name 获取兑换配置.
   * @eo.url /config
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping(value = "/config")
  public DiamondConfigCO getDiamondConfig(AppExtCommand cmd) {
    return diamondService.getDiamondConfig(cmd);
  }

  /**
   * 钻石兑换金币.
   *
   * @eo.name 钻石兑换金币.
   * @eo.url /exchange
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping(value = "/exchange")
  public BigDecimal diamondExchangeGold(@RequestBody @Validated UserBankExchangeGoldCmd cmd) {
    return salaryDiamondService.exchangeGoldYolo(cmd).getBankBalance();
  }

}
