package com.engine.salary.service.impl;

import com.engine.core.impl.Service;
import com.engine.salary.entity.taxrate.SysTaxRateDetailPO;
import com.engine.salary.entity.taxrate.TaxRateDetail;
import com.engine.salary.mapper.SysTaxRateDetailMapper;
import com.engine.salary.mapper.TaxRateDetailMapper;
import com.engine.salary.service.TaxRateDetailService;
import com.engine.salary.util.db.MapperProxyFactory;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 个税税率表明细表
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public class TaxRateDetailServiceImpl extends Service implements TaxRateDetailService {

    private TaxRateDetailMapper getTaxRateDetailMapper(){
        return MapperProxyFactory.getProxy(TaxRateDetailMapper.class);
    }

    private SysTaxRateDetailMapper getSysTaxRateDetailMapper(){
        return MapperProxyFactory.getProxy(SysTaxRateDetailMapper.class);
    }


//    @Override
//    public TaxRateDetail getByFormulaFilterData(Long taxRateBaseId, boolean isOr, Collection<FormulaFilterData> formulaFilterDataList, String tenantKey) {
//        List<TaxRateDetail> taxRateDetailPOS = listByBaseId(taxRateBaseId);
//        if (CollectionUtils.isEmpty(taxRateDetailPOS)) {
//            return null;
//        }
//        // 根据公式中的条件过滤出个税税率表明细
//        return TaxRateDetailBO.filter(taxRateDetailPOS, isOr, formulaFilterDataList);
//    }

    @Override
    public List<TaxRateDetail> listByBaseId(Long taxRateBaseId) {
        // 查询系统默认税率表的明细
        List<SysTaxRateDetailPO> sysTaxRateDetailPOS = getSysTaxRateDetailMapper().listByBaseId(taxRateBaseId);
        if (CollectionUtils.isNotEmpty(sysTaxRateDetailPOS)) {
            return sysTaxRateDetailPOS.stream()
                    .map(sysTaxRateDetailPO -> {
                        TaxRateDetail taxRateDetailPO = new TaxRateDetail();
                        BeanUtils.copyProperties(sysTaxRateDetailPO, taxRateDetailPO);
                        return taxRateDetailPO;
                    }).collect(Collectors.toList());
        }

        // 查询自定义税率表的明细
        return getTaxRateDetailMapper().listByBaseId(taxRateBaseId);
    }

    @Override
    public void deleteByBaseIds(Collection<Long> taxRateBaseIds) {
        getTaxRateDetailMapper().deleteByBatchIds(taxRateBaseIds);
    }
}
