<?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\NodeDataFilterableSet;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeDatas;
use CouponsPlus\App\Coupon\Tree\Factories\TestableGroupFactoryFromDataInterface;

class SetFiltererFromNodeData implements NodeDataFilterableSet
{
    private TestableGroupFactoryFromDataInterface $testableGroupFactory;

    public function __construct(TestableGroupFactoryFromDataInterface $testableGroupFactory)
    {
        $this->testableGroupFactory = $testableGroupFactory;
    } 

    public function filterSet(ItemsSet $itemsSet, NodeData $nodeData, NodeDatas $relatedNodeDatas): ItemsSet
    {
        (object) $testableGroup = $this->testableGroupFactory->create($nodeData->getTestable());

        return $testableGroup->filterSet($itemsSet);
    } 
}