package com.red.circle.other.app.command.activity.query;

import com.fasterxml.jackson.core.type.TypeReference;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.dto.clientobject.game.GameKingDataCO;
import com.red.circle.other.infra.database.cache.service.other.GameKingActivityCacheService;
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.Service;

/**
 * 游戏王历史记录 - 每周固定活动.
 *
 * @author pengshigang on 2021/12/29.
 */
@Service
@RequiredArgsConstructor
public class GameKingHistoryQueryExe {

  private final GameKingActivityCacheService gameKingActivityCacheService;

  public List<GameKingDataCO> execute(AppExtCommand cmd) {

    String jsonStr = gameKingActivityCacheService.getKingHistory(cmd.requireReqSysOriginEnum());
    if (StringUtils.isBlank(jsonStr)) {
      return null;
    }

    return Optional.ofNullable(JacksonUtils.readValue(jsonStr, new
            TypeReference<List<GameKingDataCO>>() {
            }))
        .orElse(null);

  }


}
