package com.red.circle.other.app.service.activity;

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.enums.WeekLeaderboardEnum;
import com.red.circle.other.app.command.activity.query.LastWeekFirstPlaceQueryExe;
import com.red.circle.other.app.command.activity.query.WeekStarCountDownQueryExe;
import com.red.circle.other.app.command.activity.query.WeekStarGiftRankingQueryExe;
import com.red.circle.other.app.command.activity.query.WeekStarHistoryTop1QueryExe;
import com.red.circle.other.app.command.activity.query.WeekStarRewardQueryExe;
import com.red.circle.other.app.command.activity.query.WeekStarStartEndTimeQueryExe;
import com.red.circle.other.app.command.activity.query.WeekStarThisWeeksGiftQueryExe;
import com.red.circle.other.app.command.activity.WeekStarExchangeExe;
import com.red.circle.other.app.dto.clientobject.activity.LastWeekStarGiftUserRankCO;
import com.red.circle.other.app.dto.clientobject.activity.UserRankCO;
import com.red.circle.other.app.dto.clientobject.activity.WeekStarGiftUserRankCO;
import com.red.circle.other.app.dto.clientobject.activity.WeekStarHistoryVO;
import com.red.circle.other.app.dto.clientobject.gift.GiftConfigCO;
import com.red.circle.other.app.dto.cmd.activity.WeekStarGiftQueryCmd;
import com.red.circle.other.app.dto.cmd.activity.WeekStarRankingQueryCmd;
import com.red.circle.other.app.dto.cmd.activity.WeekStarExchangeCmd;
import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum;
import com.red.circle.other.inner.enums.activity.WeekStarGiftTypeEnum;
import com.red.circle.other.inner.model.dto.activity.props.ActivityResource;
import com.red.circle.other.inner.model.dto.material.FragmentsBackpackDTO;
import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 周星相关 实现.
 *
 * @author pengliang on 2021/4/19
 */
@Service
@RequiredArgsConstructor
public class WeekStarServiceImpl implements WeekStarService {

  private final WeekStarRewardQueryExe weekStarRewardQueryExe;
  private final WeekStarCountDownQueryExe weekStarCountDownQueryExe;
  private final LastWeekFirstPlaceQueryExe lastWeekFirstPlaceQueryExe;
  private final WeekStarGiftRankingQueryExe weekStarGiftRankingQueryExe;
  private final WeekStarHistoryTop1QueryExe weekStarHistoryTop1QueryExe;
  private final WeekStarStartEndTimeQueryExe weekStarStartEndTimeQueryExe;
  private final WeekStarThisWeeksGiftQueryExe weekStarThisWeeksGiftQueryExe;
  private final WeekStarExchangeExe weekStarExchangeExe;

  @Override
  public WeekStarGiftUserRankCO getGiftRanking(WeekStarRankingQueryCmd cmd) {
    return weekStarGiftRankingQueryExe.execute(cmd);
  }

  private WeekStarGiftQueryCmd convertWeekStarGiftQueryCmd(WeekStarRankingQueryCmd cmd) {
    WeekStarGiftQueryCmd giftQueryCmd = new WeekStarGiftQueryCmd();
    giftQueryCmd.setReqSysOrigin(cmd.getReqSysOrigin());
    if (Objects.equals(cmd.getType(), WeekLeaderboardEnum.THIS_WEEK)) {
      giftQueryCmd.setType(WeekStarGiftTypeEnum.THIS_WEEK);
    }
    if (Objects.equals(cmd.getType(), WeekLeaderboardEnum.LAST_WEEK)) {
      giftQueryCmd.setType(WeekStarGiftTypeEnum.LAST_WEEK);
    }
    return giftQueryCmd;
  }

  @Override
  public List<GiftConfigCO> listGift(WeekStarGiftQueryCmd cmd) {
    return weekStarThisWeeksGiftQueryExe.execute(cmd);
  }

  @Override
  public List<ActivityResource> listReward(AppExtCommand cmd) {
    return weekStarRewardQueryExe.execute(cmd);
  }

  @Override
  public String countDown() {
    return weekStarCountDownQueryExe.execute();
  }

  @Override
  public String weekStarStartEndTime() {
    return weekStarStartEndTimeQueryExe.execute();
  }

  @Override
  public List<LastWeekStarGiftUserRankCO> lastWeekFirstPlace(AppExtCommand cmd) {
    return lastWeekFirstPlaceQueryExe.execute(cmd);
  }

  @Override
  public UserRankCO getMyRank(WeekStarRankingQueryCmd cmd) {
    return weekStarGiftRankingQueryExe.myRank(cmd);
  }

  @Override
  public List<WeekStarHistoryVO> getHistoryTop1(AppExtCommand cmd) {
    return weekStarHistoryTop1QueryExe.execute(cmd);
  }

  @Override
  public Long exchange(WeekStarExchangeCmd cmd) {
    return weekStarExchangeExe.execute(cmd);
  }

  @Override
  public List<ActivityResource> listActivityResource(SysOriginPlatformEnum sysOrigin, PropsActivityTypeEnum propsActivityTypeEnum) {
    return weekStarExchangeExe.listActivityResource(sysOrigin, propsActivityTypeEnum);
  }

  @Override
  public List<FragmentsBackpackDTO> listFragmentsByUserId(Long userId, Set<Long> fragmentsIds) {
    return weekStarExchangeExe.listFragmentsByUserId(userId, fragmentsIds);
  }
}
