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

/**
 * sets the sort order for this itemsset based on the current branch
 */
class SetFiltererWithOrderFromBranch extends SetFiltererFromNodeDataDecorator implements NodeDataFilterableSet
{
    public function filterSet(ItemsSet $itemsSet, NodeData $nodeData, NodeDatas $relatedNodeDatas): ItemsSet
    {
        /**
         * This fatory creates a sorter fro the brahnch
         * eg: gets the branch type and from that decides what sorter to use
         * eg 2: if its a offers branch, then gets the prerefred store from the offer types
         *      if its a tiered branch, use a default sorter
         */
        $sorterFactory = new ItemsSetSorterFactoryFromBranch;
        // were going to set the order from the branch, if any then we'll dispatch to the other filterableset
        // so somthing like:
        $itemsSet->setItemsSorter($sorterFactory->create($nodeData->getBranch()));

        $this->setFilterer->filterSet($itemsSet, $nodeData, $relatedNodeDatas);
    }
}