<?php

declare(strict_types=1);

namespace apexl\Io\dto\Relationship\Decorators;

use apexl\Io\interfaces\QueryDecorator;
use apexl\Io\interfaces\RelationshipInterface;
use apexl\Vault\interfaces\driver;

final readonly class Composite implements QueryDecorator
{
    /** @var list<QueryDecorator> */
    public array $decorators;

    public function __construct(QueryDecorator ...$decorators)
    {
        $this->decorators = array_values($decorators);
    }

    public function decorate(RelationshipInterface $relationship, driver $query): driver
    {
        foreach ($this->decorators as $decorator) {
            $query = $decorator->decorate($relationship, $query);
        }
        return $query;
    }
}
