<?php

declare(strict_types=1);

namespace KupShop\ComponentsBundle\Resources\upgrade;

class SectionsUpgrade extends \UpgradeNew
{
    private const SEARCH_SECTION_ID = -1;

    public function check_searchSection(): bool
    {
        return sqlQueryBuilder()->select('COUNT(*)')
            ->from('sections', 's')
            ->andWhere('s.id = :id')
            ->setParameter('id', self::SEARCH_SECTION_ID)
            ->execute()
            ->fetchOne() == 0;
    }

    /** ComponentsBundle: Create search section with ID=-1 */
    public function upgrade_searchSection(): void
    {
        sqlQueryBuilder()->insert('sections')
            ->directValues([
                'id' => -1,
                'name' => 'Vyhledávání',
                'figure' => 'Y',
                'show_in_search' => 'N',
            ])
            ->execute();

        $this->upgradeOK();
    }
}
