<?php

namespace domain\Document\Document;

use domain\Document\DeliveryNote\DeliveryNoteRepository;
use domain\Document\Invoice\InvoiceRepository;
use domain\Document\Quotation\QuotationRepository;
use domain\_\AbstractRepository;

class DocumentRepository extends AbstractRepository
{
    protected DeliveryNoteRepository $deliveryNoteRepository;
    protected InvoiceRepository $invoiceRepository;
    protected QuotationRepository $quotationRepository;

    public function loadDependencies(): void
    {
        $this->deliveryNoteRepository = $this->loadService(DeliveryNoteRepository::class);
        $this->invoiceRepository = $this->loadService(InvoiceRepository::class);
        $this->quotationRepository = $this->loadService(QuotationRepository::class);
    }

    public function getDefaultOptionsSearch(): array
    {
        return [];
    }

    public function findOneDocumentByIdAndClass($idDocument, $classDocument)
    {
        $model = null;

        if($idDocument) {
            if($classDocument == 'DeliveryNote') {
                $model = $this->deliveryNoteRepository->findOneDeliveryNoteById($idDocument);
            }
            elseif($classDocument == 'Quotation') {
                $model = $this->quotationRepository->findOneQuotationById($idDocument);
            }
            elseif($classDocument == 'Invoice') {
                $model = $this->invoiceRepository->findOneInvoiceById($idDocument);
            }
        }

        return $model;
    }
}