package com.ag.account.detail.impl;

import com.ag.account.detail.AccountDetail;
import com.ag.account.feeUtil.CarStepUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.ContractItem;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.SourceProperty;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.Assert;

/**
 * 阶梯单价
 */
public class StepRateDetail extends AccountDetail {

    protected void calcBefore(BizVO bizVO, SourceProperty property){
        Assert.notNull(property.getProperty().containsKey(ICondition.QUANTITY), "计价单位为数量时，请求参数中QUANTITY不允许为空!");
    }

    @Override
    protected Double getQuantity(JSONObject property, ContractItem contractItem){
        return property.getDouble(ICondition.QUANTITY);
    }

    @Override
    protected void calcByUnit(BizVO bizVO, SourceProperty source, FeeDetail detail){
        CarStepUtil.calcAmount(source.getTariffVO(), detail);
        detail.setStRate(detail.getCalcMoney());
        detail.setActualRate(detail.getStRate());
        detail.setCalcMoney(detail.getStRate() * detail.getQuantity());
        detail.setStMoney(detail.getCalcMoney());//标准金额
        detail.setFinalMoney(detail.getCalcMoney());//最终金额
    }
}
