<?php

namespace CouponsPlus\App\Coupon\Tree\Sets;

use CouponsPlus\App\Coupon\Tree\TestableGroup;
use CouponsPlus\Original\Collections\Collection;
use CouponsPlus\App\Coupon\Tree\SequentialTestableGroup;
use CouponsPlus\App\Conditions\Abilities\TestableComposite;
use CouponsPlus\App\Coupon\Tree\Sets\Abilities\ItemsSetSource;
use CouponsPlus\App\Coupon\Tree\Sets\Abilities\ItemsSetSourcePath;
use CouponsPlus\App\Coupon\Tree\Abilities\TestableCompositeCollection;

class SequentialItemsSetSourcePath implements ItemsSetSourcePath
{
    protected Collection $steps;

    /**
     * @param TestableComposite[] $steps
     */
    public function __construct(array $steps)
    {
        $this->steps = new Collection($steps);
    }

    /**
     * @return TestableComposite&TestableCompositeCollection
     */
    public function getTestableComposite()
    {
        /**
         * This will create a new sequential testable group wit all the steps
         */
        return new TestableGroup(
            new SequentialTestableGroup,
            $this->steps
        );
    }

    public function getSteps(): Collection
    {
        return $this->steps;
    }

    public function addStep(ItemsSetSource $itemsSetSource)
    {
        $this->steps->push($itemsSetSource->getTestableComposite());
    }

    public function hasSteps(): bool
    {
        return $this->steps->haveAny();
    }

    /**
     * will probably add the composite to the last step
     */
    public function addTestableComposite(TestableComposite $testableComposite)
    {
        // TODO: Implement addTestableComposite() method.
    }
}