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

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.account.domain.AccountVO;
import com.ruoyi.ss.account.domain.enums.AccountType;
import com.ruoyi.ss.account.service.AccountService;
import com.ruoyi.ss.channel.domain.ChannelQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ss.channelWithdraw.mapper.ChannelWithdrawMapper;
import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdraw;
import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdrawVO;
import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdrawQuery;
import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService;

/**
 * 提现渠道Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-02
 */
@Service
public class ChannelWithdrawServiceImpl implements ChannelWithdrawService
{
    @Autowired
    private ChannelWithdrawMapper channelWithdrawMapper;

    @Autowired
    private AccountService accountService;

    /**
     * 查询提现渠道
     *
     * @param channelId 提现渠道主键
     * @return 提现渠道
     */
    @Override
    public ChannelWithdrawVO selectChannelWithdrawByChannelId(Long channelId)
    {
        return channelWithdrawMapper.selectChannelWithdrawByChannelId(channelId);
    }

    /**
     * 查询提现渠道列表
     *
     * @param channelWithdraw 提现渠道
     * @return 提现渠道
     */
    @Override
    public List<ChannelWithdrawVO> selectChannelWithdrawList(ChannelWithdrawQuery channelWithdraw)
    {
        return channelWithdrawMapper.selectChannelWithdrawList(channelWithdraw);
    }

    /**
     * 新增提现渠道
     *
     * @param channelWithdraw 提现渠道
     * @return 结果
     */
    @Override
    public int insertChannelWithdraw(ChannelWithdraw channelWithdraw)
    {
        return channelWithdrawMapper.insertChannelWithdraw(channelWithdraw);
    }

    /**
     * 修改提现渠道
     *
     * @param channelWithdraw 提现渠道
     * @return 结果
     */
    @Override
    public int updateChannelWithdraw(ChannelWithdraw channelWithdraw)
    {
        return channelWithdrawMapper.updateChannelWithdraw(channelWithdraw);
    }

    /**
     * 批量删除提现渠道
     *
     * @param channelIds 需要删除的提现渠道主键
     * @return 结果
     */
    @Override
    public int deleteChannelWithdrawByChannelIds(Long[] channelIds)
    {
        return channelWithdrawMapper.deleteChannelWithdrawByChannelIds(channelIds);
    }

    /**
     * 删除提现渠道信息
     *
     * @param channelId 提现渠道主键
     * @return 结果
     */
    @Override
    public int deleteChannelWithdrawByChannelId(Long channelId)
    {
        return channelWithdrawMapper.deleteChannelWithdrawByChannelId(channelId);
    }

    @Override
    public List<ChannelWithdrawVO> selectEnabledList(Long userId) {
        // 查询用户账户列表
        List<AccountVO> accountList = accountService.selectByUserId(userId);
        if (CollectionUtils.isEmptyElement(accountList)) {
            return Collections.emptyList();
        }
        // 查询渠道列表
        ChannelWithdrawQuery query = new ChannelWithdrawQuery();
        query.setAccountTypes(CollectionUtils.map(accountList, AccountVO::getAccountType));
        query.setEnabled(true);
        return this.selectChannelWithdrawList(query);
    }

    @Override
    public List<ChannelWithdrawVO> selectEnabledList() {
        // 查询渠道列表
        ChannelWithdrawQuery query = new ChannelWithdrawQuery();
        query.setEnabled(true);
        return this.selectChannelWithdrawList(query);
    }
}
