<?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->loadQuery(InvoiceRepositoryQuery::class);
    }

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

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