<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiShared\Types;

use KupShop\KupShopBundle\Context\LanguageContext;
use TheCodingMachine\GraphQLite\Annotations\Autowire;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;

/**
 * @Type()
 */
class Language
{
    private $language;

    public function __construct(\KupShop\I18nBundle\Entity\Language $language)
    {
        $this->language = $language;
    }

    /**
     * Kód (ISO 639-1).
     *
     * @Field()
     */
    public function getCode(): string
    {
        return $this->language->getId();
    }

    /**
     * Název.
     *
     * @Field()
     */
    public function getName(): string
    {
        return $this->language->getName();
    }

    /**
     * @Field()
     *
     * @Autowire(for="$languageContext")
     */
    public function getIsActive(LanguageContext $languageContext): bool
    {
        return $languageContext->getActiveId() === $this->language->getId();
    }
}
