<?php

declare(strict_types=1);

namespace Gls\GlsPoland\PrestaShop\Hook\Front;

use Gls\GlsPoland\PrestaShop\Hook\HookInterface;
use Gls\GlsPoland\PrestaShop\Order\OrderParcelShopPersister;

final class ActionObjectOrderAddAfter implements HookInterface
{
    public const HOOK_NAME = 'actionObjectOrderAddAfter';

    private $persister;

    public function __construct(OrderParcelShopPersister $persister)
    {
        $this->persister = $persister;
    }

    /**
     * @param array{object?: mixed} $parameters
     */
    public function execute(array $parameters): void
    {
        $order = $parameters['object'] ?? null;

        if (!$order instanceof \Order) {
            return;
        }

        $this->persister->persistForOrder($order);
    }
}
