/**
 * Avisa cuando un producto queda con poco stock. No sabe de dónde sale el
 * stock ni cómo se envía el aviso: recibe las dos cosas por el constructor,
 * como interfaces.
 */
public class StockMonitor {
    private final StockLevels levels;
    private final Notifier notifier;
    private final int threshold;

    public StockMonitor(StockLevels levels, Notifier notifier, int threshold) {
        this.levels = levels;
        this.notifier = notifier;
        this.threshold = threshold;
    }

    /** Revisa un producto; avisa si le quedan menos de threshold unidades. */
    public void check(String product) {
        int units = levels.unitsOf(product);
        if (units < threshold) {
            notifier.send("Stock bajo: " + product + " (" + units + ")");
        }
    }
}
