<?php
/**
 * Copyright since 2025 InPost S.A.
 *
 * For the full license information, please view the LICENSE file bundled with the module.
 *
 * @author InPost S.A.
 * @copyright since 2025 InPost S.A.
 * @license MIT
 */

declare(strict_types=1);

namespace InPost\International\Shipment\Order;

use InPost\International\Shipment\Message\CreateShipmentCommand;

if (!defined('_PS_VERSION_')) {
    exit;
}

final class ChainCommandBuilder implements CreateShipmentCommandBuilderInterface
{
    /**
     * @var iterable<CreateShipmentCommandBuilderInterface>
     */
    private $commandBuilders;

    /**
     * @param iterable<CreateShipmentCommandBuilderInterface> $commandBuilders
     */
    public function __construct(iterable $commandBuilders)
    {
        $this->commandBuilders = $commandBuilders;
    }

    public function buildCommand(CreateShipmentCommand $command, \Order $order): void
    {
        foreach ($this->commandBuilders as $builder) {
            $builder->buildCommand($command, $order);
        }
    }
}
