<?php

declare(strict_types=1);

namespace Autogedal\Reduceri\Plugin\ShopbySeo;

use Amasty\ShopbySeo\Helper\Url as SeoUrlHelper;
use Magento\Framework\App\RequestInterface;

class EnableSeoUrlGeneration
{
    public function __construct(
        private readonly RequestInterface $request
    ) {}

    /**
     * Force SEO URL generation on /reduceri/* pages.
     *
     * seofyUrl() skips transformation when the current module name is not in its
     * hardcoded allowedModules list (['catalog', 'ambrand', 'amshopby']). Our module
     * 'reduceri' is not there, so filter links would remain as query-param URLs.
     * Passing skipModuleCheck=true bypasses that guard.
     */
    public function beforeSeofyUrl(
        SeoUrlHelper $subject,
        string $url,
        ?int $categoryId = null,
        bool $skipModuleCheck = false
    ): array {
        if (!$skipModuleCheck && $this->request->getModuleName() === 'reduceri') {
            $skipModuleCheck = true;
        }

        return [$url, $categoryId, $skipModuleCheck];
    }
}
