package com.ruoyi.ss.account.service.impl;

import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.account.domain.AccountVO;
import com.ruoyi.ss.account.service.AccountAssembler;
import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdrawVO;
import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wjh
 * 2024/9/18
 */
@Service
public class AccountAssemblerImpl implements AccountAssembler {
    @Autowired
    private ChannelWithdrawService channelWithdrawService;

    /**
     * 拼接渠道是否启用
     *
     * @param list
     */
    @Override
    public void assembleChannelEnabled(List<AccountVO> list) {
        if (CollectionUtils.isEmptyElement(list)) {
            return;
        }

        List<ChannelWithdrawVO> channelList = channelWithdrawService.selectEnabledList();

        for (AccountVO account : list) {
            ChannelWithdrawVO channel = channelList.stream()
                    .filter(item -> item.getAccountType() != null && item.getAccountType().equals(account.getAccountType()))
                    .findFirst()
                    .orElse(null);
            account.setChannelEnabled(channel != null);
        }

    }
}
