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

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.activity.ExclusiveGiftCO;
import com.red.circle.other.app.dto.clientobject.activity.ExclusiveGiftTopCO;
import com.red.circle.other.infra.database.cache.service.other.GiftCacheService;
import com.red.circle.tool.core.json.JacksonUtils;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 活动-专属礼物榜单.
 * </p>
 *
 * @author pengshigang
 * @since 2022-01-17
 */
@Service
@RequiredArgsConstructor
public class ExclusiveGiftTopQueryExe {

  private final GiftCacheService giftCacheService;

  public ExclusiveGiftCO execute(AppExtCommand cmd) {

    return new ExclusiveGiftCO()
        .setLastGifts(Optional
            .ofNullable(JacksonUtils
                .readValue(giftCacheService.getListLastWeekExclusive(cmd.requireReqSysOriginEnum()),
                    new TypeReference<List<ExclusiveGiftTopCO>>() {
                    })).orElse(Lists.newArrayList()))
        .setThisGifts(Optional
            .ofNullable(JacksonUtils
                .readValue(giftCacheService.getListThisWeekExclusive(cmd.requireReqSysOriginEnum()),
                    new TypeReference<List<ExclusiveGiftTopCO>>() {
                    })).orElse(Lists.newArrayList()));

  }


}
