<?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;
use CouponsPlus\App\Coupon\Tree\Abilities\TestableCompositeCollection;

class TestableGroup implements TestableComposite, TestableCompositeCollection
{
    public FilterableGroup $filterableGroup;
    public Collection $testableGroups;

    /**
     * @param FilterableGroup $filterableGroup
     * @param Collection|array $testableGroups
     */
    public function __construct(
        // this is the logic (and, or, and/or...)
        FilterableGroup $filterableGroup,
        //these are the filters/conditions, each group could be a Context or another instance of this class (TestableGroup) (TestableComposite)
        $testableGroups = null
    ) {
        $this->filterableGroup = $filterableGroup;
        $this->testableGroups = new Collection($testableGroups ?? []);
    }
    
    public function filterSet(ItemsSet $itemsSet): ItemsSet
    {
        // this is where we'll probably add the items set source
        return $this->filterableGroup->filter($this->testableGroups, $itemsSet);       
    }

    public function get(): Collection
    {
        return $this->testableGroups;
    }

    public function add(TestableComposite $testableComposite): void
    {
        $this->testableGroups->push($testableComposite);
    }
}