<?php

declare(strict_types=1);

namespace App\Repository;

use App\Entity\DrinkType;
use App\Entity\Order;
use App\Entity\OrderItem;
use Doctrine\ORM\EntityManagerInterface;

/**
 * @extends AbstractRepository<OrderItem>
 */
class OrderItemRepository extends AbstractRepository
{
    public function __construct(EntityManagerInterface $entityManager)
    {
        parent::__construct($entityManager, $entityManager->getClassMetadata(OrderItem::class));
    }

    /**
     * @return array<int, OrderItem>
     */
    public function findByOrder(Order $order): array
    {
        return $this->findBy([
            'order' => $order,
        ]);
    }

    /**
     * @return array<int, OrderItem>
     */
    public function findByDrinkType(DrinkType $drinkType): array
    {
        return $this->findBy([
            'drinkType' => $drinkType,
        ]);
    }

    public function findByOrderAndDrinkType(Order $order, DrinkType $drinkType): null|OrderItem
    {
        return $this->findOneBy([
            'order' => $order,
            'drinkType' => $drinkType,
        ]);
    }
}
