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

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.cache.service.other.GameTurntableCacheService;
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;

/**
 * 转盘h5榜单.
 *
 * @author pengshigang on 2021/12/2
 */
@Component
@RequiredArgsConstructor
public class GameTurntableTopListQueryCmdExe {

  private final GameTurntableCacheService gameTurntableCacheService;

  public List<GameUserCO> execute(AppExtCommand cmd) {

    String jsonStr = gameTurntableCacheService.listTop20(cmd.getReqSysOrigin().getOrigin());

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

  }

}
