<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiPublic\RedirectLocation;

use KupShop\GraphQLBundle\ApiPublic\Types\Redirect\RedirectLocation;
use KupShop\KupShopBundle\Config;

abstract class AbstractRedirectLocation
{
    public function getRedirectContextMap(): ?array
    {
        return $this->getConfig()['map'] ?? null;
    }

    public function getFallbackContext(): ?string
    {
        return $this->getConfig()['fallback'] ?? null;
    }

    abstract public function getActiveContext(): string;

    abstract public function getRedirectLocation($actual, $recommended): ?RedirectLocation;

    protected function getConfig(): array
    {
        $cfg = Config::get();

        return $cfg['Modules']['js_shop']['redirectLocation'] ?? [];
    }

    public function setCountryAutomatically(): bool
    {
        return true;
    }

    protected function getFlagByCountry($country): string
    {
        // TODO: make flags mapping configurable in config.php
        switch ($country) {
            case 'CZ':
                return 'cs';
            case 'DE':
                return 'de';
            case 'AT':
                return 'at';
            case 'SK':
                return 'sk';
            default:
                return 'eu';
        }
    }

    protected function getLabelByCountry($country): string
    {
        // TODO: make flags mapping configurable in config.php
        switch ($country) {
            case 'CZ':
                return 'Česká Republika';
            case 'DE':
                return 'Germany';
            case 'AT':
                return 'Austria';
            case 'SK':
                return 'Slovensko';
            default:
                return 'World';
        }
    }

    protected function getLabelByLanguage($language): string
    {
        switch ($language) {
            case 'cs':
                return 'Čeština';
            case 'de':
            case 'at':
                return 'German';
            case 'pl':
                return 'Polish';
            case 'sk':
                return 'Slovenčina';
            case 'en':
            default:
                return 'English';
        }
    }
}
