<?php
/**
 * _             _       _
 * | |____      _| | __ _| |__
 * | '_ \ \ /\ / / |/ _` | '_ \
 * | |_) \ V  V /| | (_| | |_) |
 * |_.__/ \_/\_/ |_|\__,_|_.__/.
 *
 * @author    Bwlab di Luigi Massa <info@bwlab.it>
 * @copyright since 2014 Bwlab
 * @license   proprietary
 */

declare(strict_types=1);

namespace Bwlab\Withdrawal\Repository;

if (!defined('_PS_VERSION_')) {
    exit;
}

use Bwlab\Withdrawal\Entity\WithdrawalCategoryConfig;
use Doctrine\ORM\EntityRepository;

class WithdrawalCategoryConfigRepository extends EntityRepository
{
    public function findByCategory(int $categoryId, int $shopId): ?WithdrawalCategoryConfig
    {
        return $this->createQueryBuilder('wcc')
            ->where('wcc.idCategory = :categoryId')
            ->andWhere('wcc.idShop = :shopId')
            ->setParameter('categoryId', $categoryId)
            ->setParameter('shopId', $shopId)
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();
    }

    /** @return WithdrawalCategoryConfig[] */
    public function findByShop(int $shopId): array
    {
        return $this->createQueryBuilder('wcc')
            ->where('wcc.idShop = :shopId')
            ->setParameter('shopId', $shopId)
            ->orderBy('wcc.idCategory', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
