<?php

namespace CouponsPlus\App\Coupon\Tree;

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

/**
 * Renamed from: ANDORTestableGroup
 *
 * OR INCLUSIVE will be the default now,
 */
class ORInclusiveTestableGroup implements FilterableGroup
{
    public bool $canRecordSource = true;

    public function filter(Collection $testables, ItemsSet $passedItems): ItemsSet
    {
        (object) $filteredItems = new ItemsSet([]);

        if ($this->canRecordSource) {
            $filteredItems->setSource(
                new FromTestableCompositeWithCollectionItemsSetSource(
                    new TestableGroup(new static)
                )
            );
        }

        /** @var TestableComposite $testable */
        foreach ($testables->asArray() as $testable) {
            (object) $filteredItemsForThisTestable = $testable->filterSet($passedItems);
            if ($filteredItemsForThisTestable->getItems()->haveAny()) {
                $filteredItems->addItems($filteredItemsForThisTestable, $testable);
                $filteredItems->addGroup($filteredItemsForThisTestable);
            }
        }

        return $filteredItems;
    }
}