<?php

namespace CouponsPlus\App\Coupon\Tree\Testable;

use CouponsPlus\App\Conditions\ItemsSet;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeData;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeDatas;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeDataFilterableSet;

use function CouponsPlus\App\Coupon\Tree\TestableHooks\usingBranch;

/**
 * sets the current branch so that other components may use useBranch().
 */

class ItemSetUsingBranchFilterableSet extends SetFiltererFromNodeDataDecorator implements NodeDataFilterableSet
{
    public function filterSet(ItemsSet $itemsSet, NodeData $nodeData, NodeDatas $relatedNodeDatas): ItemsSet
    {
        return usingBranch($nodeData->getBranch(), function () use ($itemsSet, $nodeData, $relatedNodeDatas) : ItemsSet {
            return $this->setFilterer->filterSet($itemsSet, $nodeData, $relatedNodeDatas);
        });
    }
}