package com.ruoyi.bst.bonus.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.bonus.domain.BonusQuery;
import com.ruoyi.bst.bonus.domain.enums.BonusArrivalType;
import com.ruoyi.bst.bonus.domain.vo.BonusDailyStatVO;
import com.ruoyi.bst.bonus.domain.vo.BonusStatVO;
import com.ruoyi.bst.bonus.mapper.BonusMapper;
import com.ruoyi.bst.bonus.service.BonusDashboard;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.dashboard.constants.StatKeys;

@Service
public class BonusDashboardImpl implements BonusDashboard {

    @Autowired
    private BonusMapper bonusMapper;

    @Override
    public BonusStatVO selectStat(BonusQuery query, List<String> keys) {
        BonusStatVO vo = new BonusStatVO();
        if (keys.contains(StatKeys.BONUS_COUNT)) {
            vo.setCount(this.selectCount(query));
        }
        if (keys.contains(StatKeys.BONUS_AMOUNT)) {
            vo.setAmount(this.selectSumOfAmount(query));
        }
        if (keys.contains(StatKeys.BONUS_WAIT_DIVIDE_AMOUNT)) {
            vo.setWaitDivideAmount(this.selectSumOfWaitAmount(query));
        }
        return vo;
    }

    @Override
    public List<BonusDailyStatVO> selectDailyStat(BonusQuery query, List<String> keys) {
        return bonusMapper.selectDailyStat(query, keys);
    }

    @Override
    public BigDecimal selectSumOfAmount(BonusQuery query) {
        return MathUtils.dv(bonusMapper.selectSumOfAmount(query));
    }

    @Override
    public BigDecimal selectSumOfUserAmount(BonusQuery query) {
        BonusQuery bonusQuery = new BonusQuery();
        BeanUtils.copyBeanProp(bonusQuery, query);
        bonusQuery.setArrivalTypes(BonusArrivalType.userList());
        return selectSumOfAmount(bonusQuery);
    }

    @Override
    public BigDecimal selectSumOfPlatformAmount(BonusQuery query) {
        BonusQuery bonusQuery = new BonusQuery();
        BeanUtils.copyBeanProp(bonusQuery, query);
        bonusQuery.setArrivalTypes(BonusArrivalType.platformList());
        return selectSumOfAmount(bonusQuery);
    }

    @Override
    public Integer selectCount(BonusQuery query) {
        return MathUtils.dv(bonusMapper.selectCount(query));
    }

    @Override
    public BigDecimal selectSumOfWaitAmount(BonusQuery query) {
        return MathUtils.dv(bonusMapper.selectSumOfWaitAmount(query));
    }
    
}
