<?php

declare(strict_types=1);

namespace KupShop\StoresBundle\Admin\lists;

use KupShop\AdminBundle\AdminList\BaseList;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\StoresBundle\Utils\StoresInStore;
use KupShop\StoresBundle\Utils\StoresTransfers;

class StoresMissingProductsList extends BaseList
{
    protected $template = 'list/storesMissingProducts.tpl';

    protected $tableDef = [
        'id' => 'stores_items_id',
        'fields' => [
            'product' => ['translate' => true, 'field' => 'p_title', 'type' => 'product', 'type_id' => 'id_product'],
            'variation' => ['translate' => true, 'field' => 'pv_title'],
            'web_store' => ['translate' => true, 'field' => 'web_in_store'],
            'stores_in_store' => ['translate' => true, 'field' => 'stores_in_store'],
        ],
    ];

    public function getQuery()
    {
        return StoresTransfers::getStoresMissingProductsQuery();
    }

    public function handleFixStore()
    {
        /** @var StoresInStore $storesInStore */
        $storesInStore = ServiceContainer::getService(StoresInStore::class);
        $affected = $storesInStore->fixInStore();

        $this->returnOK("Opraveno {$affected} položek ve skladu");
    }
}

return StoresMissingProductsList::class;
