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

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.Lists;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.dto.clientobject.game.GameUserCO;
import com.red.circle.other.infra.database.rds.service.game.GameEggCacheService;
import com.red.circle.tool.core.json.JacksonUtils;
import com.red.circle.tool.core.text.StringUtils;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 砸金蛋 排行榜.
 * </p>
 *
 * @author pengshigang
 * @since 2021-11-16
 */
@Component
@RequiredArgsConstructor
public class GameEggListExe {

  private final GameEggCacheService gameEggCacheService;

  public List<GameUserCO> execute(AppExtCommand cmd) {

    String jsonStr = gameEggCacheService.getThisDaysTop20(cmd.getReqSysOrigin().getOrigin());

    if (StringUtils.isBlank(jsonStr)) {
      return Lists.newArrayList();
    }
    return Optional
        .ofNullable(JacksonUtils.readValue(jsonStr, new TypeReference<List<GameUserCO>>() {
        }))
        .orElse(Lists.newArrayList());
  }

}
