package com.itv.till;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import static com.google.common.collect.ImmutableList.toImmutableList;

class PricerRules {
    private final ImmutableMap<String, ImmutableMap<Long, Long>> prices;

    PricerRules(ImmutableMap<String, ImmutableMap<Long, Long>> prices) {
        this.prices = prices;
    }

    boolean canPrice(String skuNumber) {
        return prices.containsKey(skuNumber);
    }

    ImmutableList<Long> getSortedDiscountAmounts(String sku, long amount) {
        return getItemRules(sku).keySet().stream()
                .filter(value -> value <= amount)
                .sorted()
                .collect(toImmutableList());
    }

    ImmutableMap<Long, Long> getItemRules(String sku) {
        return prices.get(sku);
    }
}
