<?php

declare(strict_types=1);

namespace External\HannahBundle\Admin\lists;

use Query\QueryBuilder;

class ProductsList extends \Admin\Lists\ProductsList
{
    private const PARAMETER_ID_COLOR = 55;

    public function customizeTableDef($tableDef)
    {
        $tableDef = parent::customizeTableDef($tableDef);

        $tableDef['fields']['Barva'] = [
            'field' => 'productColor',
            'spec' => function (QueryBuilder $qb) {
                $qb->addSelect('plc.value as productColor')
                    ->leftJoin('p', 'parameters_products', 'ppc', 'ppc.id_product = p.id AND ppc.id_parameter = :colorParameterId')
                    ->leftJoin('ppc', 'parameters_list', 'plc', 'plc.id = ppc.value_list')
                    ->setParameter('colorParameterId', self::PARAMETER_ID_COLOR);
            },
            'visible' => 'N',
        ];

        return $tableDef;
    }
}

return ProductsList::class;
