<?php

namespace CouponsPlus\App\Coupon\Tree;

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

use function CouponsPlus\App\Coupon\Tree\TestableHooks\useExcludedTestableTypes;

class IgnorableCardsTestableGroup extends FilterableGroupDecorator implements FilterableGroup
{
    public function filter(Collection $testables, ItemsSet $passedItems): ItemsSet
    {
        $testableTypesToIgnore = useExcludedTestableTypes();

        $allowedTestables = $testables->filter(function (DashboardCard $testable) use ($testableTypesToIgnore) {
            return !$testableTypesToIgnore->have($testable->getType());
        });

        return $this->filterableGroup->filter($allowedTestables, $passedItems);
    }
}