package com.red.circle.other.app.command.game.luckybox;

import com.google.common.collect.Lists;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.common.game.GameLuckyBoxCommon;
import com.red.circle.other.app.dto.clientobject.game.GameLuckyBoxGiftConfigDetailsCO;
import com.red.circle.other.app.dto.clientobject.game.GameLuckyBoxStandardConfigCO;
import com.red.circle.other.app.dto.clientobject.game.GameLuckyBoxTimeConfigCO;
import com.red.circle.other.infra.database.rds.entity.game.GameLuckyBoxStandardConfig;
import com.red.circle.other.infra.database.rds.service.game.GameLuckyBoxStandardConfigService;
import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * LuckyBox 获取抽奖规格、抽奖频数、抽奖礼物信息
 *
 * @author zongpubin on 2023/8/26
 */

@Component
@RequiredArgsConstructor
public class GameLuckyBoxStandardConfigQryExe {


  private final GameLuckyBoxCommon gameLuckyBoxCommon;
  private final GameLuckyBoxStandardConfigService gameLuckyBoxStandardConfigService;


  public List<GameLuckyBoxStandardConfigCO> execute(AppExtCommand cmd) {

    List<GameLuckyBoxStandardConfig> standardConfigs = gameLuckyBoxStandardConfigService.listBySysOrigin(
        cmd.getReqSysOrigin().getOrigin());
    if (CollectionUtils.isEmpty(standardConfigs)) {
      return Lists.newArrayList();
    }

    return standardConfigs.stream().map(standardConfig -> new GameLuckyBoxStandardConfigCO()
        .setId(standardConfig.getId())
        .setLotteryType(standardConfig.getLotteryType())
        .setGiftConfigDetails(getGiftInfo(standardConfig.getId(), cmd.getReqSysOrigin().getOrigin()))
        .setTimeConfigs(getTimeInfo(standardConfig.getId(), cmd.getReqSysOrigin().getOrigin()))
    ).toList();
  }

  private List<GameLuckyBoxTimeConfigCO> getTimeInfo(Long standardId, String sysOrigin) {
    return gameLuckyBoxCommon.getTimeInfo(standardId, sysOrigin);
  }

  private List<GameLuckyBoxGiftConfigDetailsCO> getGiftInfo(Long standardId, String sysOrigin) {
    return gameLuckyBoxCommon.getGiftInfo(standardId, sysOrigin);
  }
}
