<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiShared\Types\Price;

use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;

/**
 * @Type()
 */
class Currency
{
    public $currency;

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

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

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

    /**
     * Symbol.
     *
     * @Field()
     */
    public function getSymbol(): string
    {
        return $this->currency->getSymbol();
    }

    /**
     * Kurz.
     *
     * @Field()
     */
    public function getRate(): float
    {
        return $this->currency->getRate()->asFloat();
    }

    /**
     * Zaokrouhlování (0=nezaokrouhlovat, 1=haléře, 5=5 haléřů, 100=celá čísla, -5=5 korun, -10=10 korun).
     *
     * @Field()
     */
    public function getRoundType(): int
    {
        return $this->currency->getPriceRound();
    }

    /**
     * Směr zaokrouhlování (up, down, math).
     *
     * @Field()
     */
    public function getRoundDirection(): string
    {
        return $this->currency->getPriceRoundDirection();
    }

    /**
     * Počet desetinných míst pro zobrazení (0, 2, -1=dynamicky).
     *
     * @Field()
     */
    public function getPrecision(): int
    {
        return $this->currency->getPricePrecision() == 'dynamic' ? -1 : (int) $this->currency->getPricePrecision();
    }

    /**
     * Oddělovač desetinných míst.
     *
     * @Field()
     */
    public function getDecimalMark(): string
    {
        return $this->currency->getPriceDecimalMark();
    }
}
