<?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\usingSorter;

class ItemsSetSorterFromBranchFilterableSet extends SetFiltererFromNodeDataDecorator implements NodeDataFilterableSet
{
    public function filterSet(ItemsSet $itemsSet, NodeData $nodeData, NodeDatas $relatedNodeDatas): ItemsSet
    {
        (object) $itemsSetSorter = $nodeData->getBranch()->getItemsSorter();

        return usingSorter($itemsSetSorter, function () use ($relatedNodeDatas, $nodeData, $itemsSet) {
            $itemsSet1 = $this->setFilterer->filterSet($itemsSet, $nodeData, $relatedNodeDatas);

            return $itemsSet1;
        });
    }
}