package com.ruoyi.bst.withdraw.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.bst.withdraw.domain.WithdrawQuery;
import com.ruoyi.bst.withdraw.domain.enums.WithdrawStatus;
import com.ruoyi.bst.withdraw.domain.vo.WithdrawDailyStatVO;
import com.ruoyi.bst.withdraw.domain.vo.WithdrawStatVO;
import com.ruoyi.bst.withdraw.mapper.WithdrawMapper;
import com.ruoyi.bst.withdraw.service.WithdrawDashboard;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.dashboard.constants.StatKeys;

@Service
public class WithdrawDashboardImpl implements WithdrawDashboard {
    
    @Autowired
    private WithdrawMapper withdrawMapper;

    @Override
    public WithdrawStatVO selectStat(WithdrawQuery query, List<String> keys) {
        WithdrawStatVO vo = new WithdrawStatVO();
        if (keys.contains(StatKeys.WITHDRAW_SUCCESS_AMOUNT)) {
            vo.setSuccessAmount(this.selectSuccessAmount(query));
        }
        if (keys.contains(StatKeys.WITHDRAW_WAIT_VERIFY_COUNT)) {   
            vo.setWaitVerifyCount(this.selectWaitVerifyCount(query));
        }
        return vo;
    }

    @Override
    public BigDecimal selectSuccessAmount(WithdrawQuery query) {
        WithdrawQuery successQuery = new WithdrawQuery();
        BeanUtils.copyProperties(query, successQuery);
        successQuery.setStatus(WithdrawStatus.SUCCESS.getCode());
        return MathUtils.dv(withdrawMapper.selectSumOfArrivalAmount(successQuery));
    }

    @Override
    public Integer selectWaitVerifyCount(WithdrawQuery query) {
        WithdrawQuery waitVerifyQuery = new WithdrawQuery();
        BeanUtils.copyProperties(query, waitVerifyQuery);
        waitVerifyQuery.setStatus(WithdrawStatus.WAIT_VERIFY.getCode());
        return MathUtils.dv(withdrawMapper.selectCount(waitVerifyQuery));
    }

    @Override
    public List<WithdrawDailyStatVO> selectDailyStat(WithdrawQuery query, List<String> keys) {
        return withdrawMapper.selectDailyStat(query, keys);
    }

    @Override
    public BigDecimal selectSuccessServiceCharge(WithdrawQuery query) {
        WithdrawQuery successQuery = new WithdrawQuery();
        BeanUtils.copyProperties(query, successQuery);
        successQuery.setStatus(WithdrawStatus.SUCCESS.getCode());
        return MathUtils.dv(withdrawMapper.selectSumOfServiceCharge(successQuery));
    }
}
