<?php

namespace common\logic\Document\Quotation\Repository;

use common\logic\AbstractRepository;
use common\logic\Document\Quotation\Model\Quotation;

class QuotationRepository extends AbstractRepository
{
    protected QuotationRepositoryQuery $query;

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

    public function getDefaultOptionsSearch(): array
    {
        return [
            self::WITH => [],
            self::JOIN_WITH => ['user AS user_quotation', 'producer'],
            self::ORDER_BY => 'date ASC',
            self::ATTRIBUTE_ID_PRODUCER => 'quotation.id_producer'
        ];
    }

    public function findOneQuotationById(int $id): ?Quotation
    {
        return $this->createDefaultQuery()
            ->filterById($id)
            ->findOne();
    }
}