<?php

namespace common\logic\Document\Invoice\Repository;

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

class InvoiceRepository extends AbstractRepository
{
    protected InvoiceRepositoryQuery $query;

    public function loadDependencies(): void
    {
        $this->query = $this->loadService(InvoiceRepositoryQuery::class);
    }

    public function getDefaultOptionsSearch(): array
    {
        return [
            'with' => [],
            'join_with' => ['user AS user_invoice', 'producer'],
            'orderby' => 'date ASC',
            'attribute_id_producer' => 'invoice.id_producer'
        ];
    }

    public function findOneInvoiceById(int $id): ?Invoice
    {
        return Invoice::searchOne(['id' => $id]);
    }
}