<?php

it('registers queued economic invoice endpoints in economicInvoiceRoute', function (): void {
    $content = file_get_contents(app_path('routes/economicInvoiceRoute.php'));

    expect($content)->not->toBeFalse();
    expect($content)->toContain('private function ensureEconomicTransferQueueIsAvailable(): void');
    expect($content)->toContain('private function isEconomicTransferQueueAvailable(): bool');
    expect($content)->toContain("class_exists('\\\\classes\\\\economic_transfer_executor')");
    expect($content)->toContain("class_exists('\\\\classes\\\\economic_transfer_queue_schema_bootstrap')");
    expect($content)->toContain("if (!\$this->isEconomicTransferQueueAvailable()) {");
    expect($content)->toContain('$this->ensureEconomicTransferQueueIsAvailable();');
    expect($content)->not->toContain("require_once __DIR__ . '/../classes/economic_transfer_executor.php';");
    expect($content)->toContain('/economic/invoice/draft/export');
    expect($content)->toContain('/economic/invoice/export');
    expect($content)->toContain('/economic/invoice/draft/export/status');
    expect($content)->toContain('/economic/invoice/draft/export/retry');
    expect($content)->toContain('/economic/invoice/export/status');
    expect($content)->toContain('/economic/invoice/export/retry');
    expect($content)->toContain('economic_transfer_queue::TYPE_ORDER_DRAFT_EXPORT');
    expect($content)->toContain('economic_transfer_queue::TYPE_ORDER_INVOICE_EXPORT');
    expect($content)->toContain("'job_id' => \$job_id");
    expect($content)->toContain("missing queue job id in enqueue response");
    expect($content)->toContain("'mode' => 'synchronous_fallback'");
    expect($content)->toContain('ECONOMIC_INVOICE_DRAFT_EXPORT_FALLBACK');
    expect($content)->toContain('ECONOMIC_INVOICE_EXPORT_FALLBACK');
    expect($content)->toContain('private function exportOrderDraftSynchronously');
    expect($content)->toContain('private function exportOrderInvoiceSynchronously');
});

it('registers collected-invoice queue endpoints in orderInvoicesRoute', function (): void {
    $content = file_get_contents(app_path('routes/orderInvoicesRoute.php'));

    expect($content)->not->toBeFalse();
    expect($content)->toContain('private function ensureEconomicTransferQueueIsAvailable(): void');
    expect($content)->toContain('private function isEconomicTransferQueueAvailable(): bool');
    expect($content)->toContain("class_exists('\\\\classes\\\\economic_transfer_executor')");
    expect($content)->toContain("class_exists('\\\\classes\\\\economic_transfer_queue_schema_bootstrap')");
    expect($content)->toContain('$this->ensureEconomicTransferQueueIsAvailable();');
    expect($content)->toContain('private function exportCollectedInvoiceSynchronously');
    expect($content)->not->toContain("require_once __DIR__ . '/../classes/economic_transfer_executor.php';");
    expect($content)->toContain('/collected-invoices/economic');
    expect($content)->toContain('/collected-invoices/economic/queue');
    expect($content)->toContain('/collected-invoices/economic/queue/status');
    expect($content)->toContain('/collected-invoices/economic/queue/retry');
    expect($content)->toContain('/collected-invoices/economic/queue/run');
    expect($content)->toContain('/collected-invoices/stripe/book');
    expect($content)->toContain('economic_transfer_queue::TYPE_COLLECTED_INVOICE_EXPORT');
    expect($content)->toContain('processPendingByTransferType(');
    expect($content)->toContain("'job_id' => \$job_id");
    expect($content)->toContain("missing queue job id in enqueue response");
    expect($content)->toContain("requirePermission('add_collected_invoice_economic')");
    expect($content)->toContain("requirePermission('add_collected_invoice_stripe')");
    expect($content)->toContain('send_as_is must be a boolean');
    expect($content)->toContain("in_array(\$normalized_send_as_is, ['true', '1'], true)");
    expect($content)->toContain("'mode' => 'synchronous_fallback'");
    expect($content)->toContain('ADD_COLLECTED_INVOICE_ECONOMIC_FALLBACK');
    expect($content)->toContain('ADD_COLLECTED_INVOICE_STRIPE_FALLBACK');
    expect($content)->toContain("'message' => 'Stripe collected invoice export queued'");
});
