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

import com.alibaba.nacos.common.utils.StringUtils;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.task.CheckInRewardListCO;
import com.red.circle.other.app.dto.cmd.task.CheckInRewardCmd;
import com.red.circle.other.app.service.task.CheckInService;
import com.red.circle.other.infra.database.cache.key.CheckInKeys;
import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum;
import com.red.circle.other.inner.model.dto.activity.props.ActivityRewardPropsDTO;
import java.util.List;

import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
import com.red.circle.wallet.inner.endpoint.wallet.api.WalletGoldClientApi;
import com.red.circle.wallet.inner.model.dto.VipGiveawayGoldRecordDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
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 pengliang on 2020/5/29
 * @eo.api-type http
 * @eo.groupName 系统服务.签到打卡
 * @eo.path /task/check/in
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/task/check/in", produces = MediaType.APPLICATION_JSON_VALUE)
public class CheckInRestController extends BaseController {

  private final CheckInService checkInService;

  /**
   * ASWAT新打卡-奖励池.
   *
   * @eo.name ASWAT新打卡-奖励池.
   * @eo.url /list/award/pool
   * @eo.method get
   * @eo.request-type formdata
   */
  @Deprecated
  @GetMapping("/list/award/pool")
  public List<ActivityRewardPropsDTO> listRewardPool(AppExtCommand cmd) {
    return checkInService.listRewardPool(cmd);
  }

  /**
   * ASWAT新打卡-抽奖.
   *
   * @eo.name ASWAT新打卡-抽奖.
   * @eo.url /lottery
   * @eo.method post
   * @eo.request-type formdata
   */
  @Deprecated
  @PostMapping("/lottery")
  public ActivityRewardPropsDTO lottery(AppExtCommand cmd) {
    return checkInService.lottery(cmd);
  }

  /**
   * 今天是否已签到.
   */
  @GetMapping("/today")
  public Boolean checkToday(AppExtCommand cmd, String dailyKey) {
    if (StringUtils.isBlank(dailyKey)) {
      dailyKey = CheckInKeys.DAILY_CHECK_IN.getKey("DAILY_CHECK_IN_" + cmd.getReqUserId() + ZonedDateTimeAsiaRiyadhUtils.nowDateToInt());
    } else {
      dailyKey = CheckInKeys.AZIZI_CHECK_IN.getKey("AZIZI_CHECK_IN" + cmd.getReqUserId() + ZonedDateTimeAsiaRiyadhUtils.nowDateToInt());
    }
    return checkInService.checkToday(cmd, dailyKey);
  }

  /**
   * 每日签到奖励列表.
   */
  @GetMapping("/list/award")
  public CheckInRewardListCO listRewardYolo(AppExtCommand cmd, PropsActivityTypeEnum activityType) {
    if (activityType == null) {
        activityType = PropsActivityTypeEnum.DAILY_REGISTER;
    } else {
       activityType = PropsActivityTypeEnum.DAILY_REGISTER_AZIZI;
    }
    return checkInService.listReward(cmd, activityType);
  }

  /**
   * 打卡-领取奖励.
   */
  @PostMapping("/receive")
  public Integer receive(@RequestBody @Validated CheckInRewardCmd cmd) {
    return checkInService.receive(cmd);
  }

  /**
   * 最新的vip金币赠送记录
   * @param cmd
   * @return
   */
  @GetMapping("/latest-vip-record")
  public List<VipGiveawayGoldRecordDTO> getLatestVipGiveawayRecord(AppExtCommand cmd) {
    return checkInService.getLatestVipGiveawayRecords(cmd);
  }

}
