package com.ym.mec.biz.service.impl;

import com.ym.mec.biz.dal.dao.SysUserCashAccountLogDao;
import com.ym.mec.biz.dal.entity.SysUserCashAccountLog;
import com.ym.mec.biz.service.SysConfigService;
import com.ym.mec.biz.service.SysUserCashAccountLogService;
import com.ym.mec.common.constant.CommonConstants;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class SysUserCashAccountLogServiceImpl extends BaseServiceImpl<Long, SysUserCashAccountLog>  implements SysUserCashAccountLogService {
	
	@Autowired
	private SysUserCashAccountLogDao sysUserCashAccountLogDao;

	@Override
	public BaseDAO<Long, SysUserCashAccountLog> getDAO() {
		return sysUserCashAccountLogDao;
	}

	@Override
	public BigDecimal musicReturnFeeCharges(BigDecimal returnFee, Integer size) {
		String configName = SysConfigService.MUSIC_COURSE_START_RETURN_FEE_CHARGES;
		if(size == null || size == 0){
			configName = SysConfigService.MUSIC_RETURN_FEE_CHARGES;
		}
		return calcCharges(returnFee,configName);
	}

	@Override
	public BigDecimal vipReturnFeeCharges(BigDecimal returnFee, Integer size) {
		String configName = SysConfigService.VIP_1VN_COURSE_NOT_START_RETURN_FEE_CHARGES;
		if(size == null || size <= 1){
			configName = SysConfigService.VIP_1V1_COURSE_NOT_START_RETURN_FEE_CHARGES;
		}
		return calcCharges(returnFee,configName);
	}

	private BigDecimal calcCharges(BigDecimal returnFee,String configValue){
		double returnFeeCharges = 1;
		if(StringUtils.isNotEmpty(configValue)){
			returnFeeCharges = Double.parseDouble(configValue) / 100;
		}
		return returnFee.multiply(new BigDecimal(returnFeeCharges)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_HALF_UP);
	}
}