<?php

namespace common\logic\Ticket\TicketUser\Repository;

use common\logic\AbstractRepository;
use common\logic\Ticket\Ticket\Model\Ticket;
use common\logic\Ticket\TicketUser\Model\TicketUser;
use common\logic\User\User\Model\User;

class TicketUserRepository extends AbstractRepository
{
    protected TicketUserRepositoryQuery $query;

    public function loadDependencies(): void
    {
        $this->loadQuery(TicketUserRepositoryQuery::class);
    }

    /**
     * Retourne les options de base nécessaires à la fonction de recherche.
     */
    public function getDefaultOptionsSearch(): array
    {
        return [
            self::WITH => ['ticket', 'user'],
            self::JOIN_WITH => [],
            self::ORDER_BY => '',
            self::ATTRIBUTE_ID_PRODUCER => ''
        ];
    }

    public function findOneTicketUser(Ticket $ticket, User $user): ?TicketUser
    {
        return $this->createDefaultQuery()
            ->filterByTicket($ticket)
            ->filterByUser($user)
            ->findOne();
    }
}