<?php

declare(strict_types=1);

namespace External\CykloSpecialityBundle\Util;

use KupShop\GraphQLBundle\ApiPublic\RedirectLocation\RedirectShopCustom;
use KupShop\GraphQLBundle\ApiPublic\Types\Redirect\RedirectLocation;
use KupShop\KupShopBundle\Attribute\OverrideService;
use KupShop\KupShopBundle\Context\CountryContext;
use KupShop\KupShopBundle\Util\Contexts;

#[OverrideService(RedirectShopCustom::class)]
class CykloSpecialityRedirect extends RedirectShopCustom
{
    public function getActiveContext(): string
    {
        return Contexts::get(CountryContext::class)->getActiveId();
    }

    public function getRedirectLocation($actual, $recommended): ?RedirectLocation
    {
        try {
            $location = path('external_cyklospeciality_cyklospeciality_redirectbycountry', ['country' => $recommended]);
        } catch (\Exception $e) {
            return null;
        }

        return new RedirectLocation(
            $location,
            $this->getLabelByCountry($recommended),
            $this->getFlagByCountry($recommended),
            null,
            null,
        );
    }
}
