<?php

namespace CouponsPlus\App\Coupon\Tree;

use CouponsPlus\App\Conditions\Abilities\TestableComposite;
use CouponsPlus\App\Conditions\ItemsSet;
use CouponsPlus\App\Coupon\Tree\Abilities\FilterableGroup;
use CouponsPlus\Original\Collections\Collection;

class ORTestableGroup implements FilterableGroup
{
    public function filter(Collection $testables, ItemsSet $passedItems): ItemsSet
    {
        /** @var TestableComposite $testable */
        foreach ($testables->asArray() as $testable) {
            (object) $filteredItems = $testable->filterSet($passedItems);

            if ($filteredItems->getItems()->haveAny()) {
                return $filteredItems;
            }
        }

        return new ItemsSet([]);
    } 
}