package performa.orm;

import oneit.utils.math.NullArith;


public class PaymentPlan extends BasePaymentPlan
{
    private static final long   serialVersionUID    =   0L;
    public static final Double  PER_PER_JOB_AMOUNT  =   385D; 
    public static final Double  PER_PER_JOB_EXPRESS =   285D; 
    
    // This constructor should not be called
    public PaymentPlan ()
    {
        // Do not add any code to this, always put it in initialiseNewObject
    }

    
    @Override
    public String getToString() 
    {
        if(getActiveJobCount()!=null)
        {
            return getActiveJobCount().toString();
        }
        
        return super.getToString();
    }
    
    
    public Double getPerMonthSaveAmount()
    {
        if(getActiveJobCount()!=null)
        {
            return NullArith.subtract(NullArith.multiply(getActiveJobCount(), PER_PER_JOB_AMOUNT, 0D), getAmount(), 0D);
        }
        
        return null;
    }
    
    
    public Double getAmountPerJob(HiringTeam hiringTeam)
    {
        if(getActiveJobCount() != null)
        {
            return (getAmount() / getActiveJobCount()) * (hiringTeam.getCoupon() != null ? (100 - hiringTeam.getCoupon().getPercentageOff()) * 0.01 : 1);
        }
        return getAmount(); 
    }
    
    
    public Double getTotalAmount(HiringTeam hiringTeam)
    {
        return getAmount() * (hiringTeam.getCoupon() != null ? (100 - hiringTeam.getCoupon().getPercentageOff()) * 0.01 : 1);
    }
}