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

import com.google.common.collect.Lists;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.other.app.dto.clientobject.user.relation.friendcard.UserFriendCardStoreCO;
import com.red.circle.other.infra.database.cache.service.user.UserFriendshipCardConfigCacheService;
import com.red.circle.other.infra.database.rds.entity.user.user.FriendshipCardConfig;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 获得自己的友谊关系卡 .
 * </p>
 *
 * @author pengshigang
 * @since 2022-06-10
 */
@Component
@RequiredArgsConstructor
public class UserFriendCardsQryExe {

  private final UserFriendshipCardConfigCacheService userFriendshipCardConfigCacheService;

  public List<UserFriendCardStoreCO> execute(AppExtCommand cmd) {

    List<FriendshipCardConfig> cardConfigCaches = getCardConfigCaches(cmd);
    if (CollectionUtils.isEmpty(cardConfigCaches)) {
      return Lists.newArrayList();
    }

    return cardConfigCaches.stream().map(cardConfig -> new UserFriendCardStoreCO()
        .setCardType(cardConfig.getCardType())
        .setBuyCardMoney(cardConfig.getCardMoney())
        .setCardBack(cardConfig.getCardBack())
    ).collect(Collectors.toList());
  }

  private List<FriendshipCardConfig> getCardConfigCaches(AppExtCommand cmd) {
    return userFriendshipCardConfigCacheService.listSysOriginConfig(cmd.requireReqSysOrigin());
  }

}
