package org.lucci.madhoc.network.cost;

public class ThresholdedCostModel extends CostModel
{
    private double priceForOneSingleByteBelowThreshold;

    private double priceForOneSingleByteAboveThreshold;

    private int numberOfBytesThreshold;

    public void configure() throws Throwable
    {
        setPriceForOneSingleByteBelowThreshold(getSimulation()
                .getConfiguration().getDouble(
                        "price_for_one_singe_byte_below_threshold"));
        setPriceForOneSingleByteAboveThreshold(getSimulation()
                .getConfiguration().getDouble(
                        "price_for_one_singe_byte_above_threshold"));
        setNumberOfBytesThreshold(getSimulation().getConfiguration()
                .getInteger("number_of_bytes_threshold"));
    }

    @Override
    public double getCost(int numberOfBytes, int history)
    {
        if (history < getNumberOfBytesThreshold())
        {
            return getPriceForOneSingleByteBelowThreshold() * numberOfBytes;
        } else
        {
            return getPriceForOneSingleByteAboveThreshold() * numberOfBytes;
        }
    }

    public int getNumberOfBytesThreshold()
    {
        return numberOfBytesThreshold;
    }

    public void setNumberOfBytesThreshold(int numberOfBytesThreshold)
    {
        this.numberOfBytesThreshold = numberOfBytesThreshold;
    }

    public double getPriceForOneSingleByteAboveThreshold()
    {
        return priceForOneSingleByteAboveThreshold;
    }

    public void setPriceForOneSingleByteAboveThreshold(
            double priceForOneSingleByteAfterThreshold)
    {
        this.priceForOneSingleByteAboveThreshold = priceForOneSingleByteAfterThreshold;
    }

    public double getPriceForOneSingleByteBelowThreshold()
    {
        return priceForOneSingleByteBelowThreshold;
    }

    public void setPriceForOneSingleByteBelowThreshold(
            double priceForOneSingleByteUntilThreshold)
    {
        this.priceForOneSingleByteBelowThreshold = priceForOneSingleByteUntilThreshold;
    }

}