<?php

use KupShop\AdminBundle\AdminList\BaseList;

class CurrenciesList extends BaseList
{
    protected $tableDef = [
        'id' => 'id',
        'fields' => [
            'Název' => ['field' => 'name'],
            'Kód' => ['field' => 'id'],
            'Symbol' => ['field' => 'symbol'],
            /*'Zaokrouhlení' => ['field' => 'price_round', 'render' => 'renderRound'],
            'Zaokrouhlení objednávky' => ['field' => 'price_round_order', 'render' => 'renderRoundOrder'],
            'Směr zaokrouhlení' => ['field' => 'price_round_direction', 'render' => 'renderDirection'],
            'Formát' => ['field' => 'price_precision', 'render' => 'renderPrecision'],
            'Oddělovač' => ['field' => 'price_decimal_mark'],*/
            'Kurz' => ['field' => 'rate'],
            'Korekce kurzu' => ['field' => 'corrections'],
            'Automatická synchronizace' => ['field' => 'sync', 'render' => 'renderSync'],
            'Poslední synchronizace' => ['field' => 'sync_date_update', 'render' => 'renderDate'],
        ],
    ];

    private $rounds = [
        0 => 'nezaokrouhlovat',
        1 => 'haléře ',
        5 => 'na 5-ti haléře',
        10 => 'na 10-ti haléře',
        50 => 'na 50-ti haléře',
        100 => 'na celá čísla',
    ];

    private $directions = [
        'up' => 'nahoru',
        'down' => 'dolů',
        'math' => 'matematicky',
    ];

    private $precisions = [
        0 => 'žádné desetinné místo (10 Kč)',
        2 => 'dvě desetinná místa (10,15 Kč)',
        'dynamic' => 'dvě desetinná místa dle potřeby',
    ];

    public function renderDate($values, $column)
    {
        if ($values[$column['field']] == 0) {
            return 'nesynchronizováno';
        }

        return $values[$column['field']];
    }

    public function renderSync($values, $column)
    {
        if ($values[$column['field']] == 'Y') {
            return 'ano';
        }

        return 'ne';
    }

    public function renderPrecision($values, $column)
    {
        return $this->precisions[$values[$column['field']]];
    }

    public function renderDirection($values, $column)
    {
        return $this->directions[$values[$column['field']]];
    }

    public function renderRound($values, $column)
    {
        return $this->rounds[$values[$column['field']]];
    }

    public function renderRoundOrder($values, $column)
    {
        return $this->rounds[$values[$column['field']]];
    }

    public function getQuery()
    {
        $qb = sqlQueryBuilder()
            ->select('id, name, symbol, price_round, price_round_order, price_round_direction, 
                      price_precision, price_decimal_mark, rate, sync, corrections, sync_date_update')
            ->from('currencies');

        return $qb;
    }

    private function getTranslate($key, $section = null, $silent = false)
    {
        return translate($key, $section, $silent);
    }
}
