<?php

namespace CouponsPlus\App\Coupon\Tree\ItemSetsToDiscount;

use CouponsPlus\App\Coupon\Tree\Abilities\ItemSetToDiscountHandler;
use CouponsPlus\App\Coupon\Tree\Abilities\ItemSetToDiscountCollectionHandler;

class IncompleteItemSetToDiscountCollectionHandler implements ItemSetToDiscountCollectionHandler
{

    protected ItemSetToDiscountHandler $itemSetToDiscountHandler;

    public function __construct(ItemSetToDiscountHandler $itemSetToDiscountHandler)
    {
        $this->itemSetToDiscountHandler = $itemSetToDiscountHandler;
    }

    public function handle(ItemsSetToDiscountCollection $itemsSetsToDiscount)
    {
        $itemsSetsToDiscount->getSetsThatCannotFillRequiredQuantity()->forEvery(function(ItemsSetToDiscount $itemsSetToDiscount) : void {
            /**
             * Why can they not fill it?
             *
             * -can they be added to the cart? add them (execution ends here for this instance)
             * -cannot be added to the cart? react based on this. possible reactions:
             *  -show a notification
             *  -display a list of items that the user can choose from
             *  -etc
             */
            $this->itemSetToDiscountHandler->handle($itemsSetToDiscount);
        });
    }
}