package com.red.circle.wallet.infra.database.rds.service.impl;

import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.wallet.domain.wallet.WalletBizType;
import com.red.circle.wallet.infra.database.rds.dao.WalletRemarksDAO;
import com.red.circle.wallet.infra.database.rds.entity.WalletRemarks;
import com.red.circle.wallet.infra.database.rds.service.WalletRemarksService;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;

/**
 * 钱包备注 服务实现.
 *
 * @author pengliang on 2023/7/3
 */
@Service
public class WalletRemarksServiceImpl extends
    BaseServiceImpl<WalletRemarksDAO, WalletRemarks> implements WalletRemarksService {

  @Override
  public Map<String, String> mapRemarkValue(WalletBizType bizType, Set<String> bizIds) {

    if (Objects.isNull(bizType) || CollectionUtils.isEmpty(bizIds)) {
      return CollectionUtils.newHashMap();
    }

    List<WalletRemarks> walletRemarks = query()
        .eq(WalletRemarks::getBizType, bizType.getType())
        .in(WalletRemarks::getBizId, bizIds)
        .list();

    if (CollectionUtils.isEmpty(walletRemarks)) {
      return CollectionUtils.newHashMap();
    }
    return walletRemarks.stream()
        .collect(Collectors.toMap(WalletRemarks::getBizId, Function.identity(), (v0, v1) -> v0))
        .entrySet().stream()
        .collect(Collectors.toMap(Entry::getKey, val -> val.getValue().getContent()));
  }
}
