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

/**
 * This will make the filters function as a 'test' or 'condition' mode only
 * which mean that the filters will only check if the items can be filtered
 * if they can, THE PASSED ItemsSet will be returned instead of the filtered items
 * essentially working like if they were Conditions
 */
class TestModeTestableGroup implements TestableComposite
{
    public function __construct(
        protected FilterableGroup $filterableGroup,
        protected Collection $testablesGroup
    ) {}
    
    public function filterSet(ItemsSet $itemsSet): ItemsSet
    {
        (object) $hasValidFilteredItems = $this->filterableGroup->filter($this->testablesGroup, $itemsSet);       

        if ($hasValidFilteredItems) {
            return $itemsSet;
        }

        return new ItemsSet([]);
    } 
}