<?php

namespace KupShop\PohodaBundle\Utils\Exporters;

use KupShop\PohodaBundle\Utils\PohodaBase;
use KupShop\PohodaBundle\Utils\Tools\PohodaOrderExporter;
use Symfony\Contracts\Service\Attribute\Required;

class OrderInvoiceCorrectiveTaxExporter
{
    use \DatabaseCommunication;
    use PohodaBase;

    protected array $IDs;

    #[Required]
    public PohodaOrderExporter $orderExporter;

    public function getData()
    {
        return $this->orderExporter->getXML($this->IDs, true);
    }

    public function processData($xml = null)
    {
        $this->pohodaConnector->prepareSyncTime();

        if (!$xml) {
            $xml = $this->getData();
        }

        if ($xml) {
            $correctiveDocumentRequest = $this->transformHelper->baseTransform($xml, $this->transformHelper->loadXslt('orderCorrectiveTaxDocument.xsl'));

            $request = $this->replace($correctiveDocumentRequest->saveXML());

            $this->addRequestLog('Corrective tax document export', $request);
            $response = $this->pohodaConnector->sendRequest($request);
            $this->addResponseLog('Corrective tax document export', $response);

            if ($response) {
                $this->processResponse($response);
            }
        }

        $this->pohodaConnector->setLastSyncTime('ordersOut');
    }

    public function processResponse($xmlStringResponse)
    {
    }

    public function setIDs($IDs): void
    {
        $this->IDs = $IDs;
    }

    public function getIDs(): array
    {
        return $this->IDs;
    }
}
