← Code-Übersicht

DiscoverInvoicesUseCase.php

Pfad: src/Application/Rechnung/DiscoverInvoicesUseCase.php

Ext: php

Größe: 1371 Bytes

Geändert: 2026-07-16 14:13:09+02

<?php
declare(strict_types=1);

namespace Demo\Application\Rechnung;

use Demo\Domain\Rechnung\InvoiceLoggerPort;
use Demo\Domain\Rechnung\SourceInvoice;
use Demo\Domain\Rechnung\WetellSourcePort;

/**
 * Use Case: Quelle anmelden, Liste ermitteln, Duplikate vorselektieren.
 */
final class DiscoverInvoicesUseCase
{
    /**
     * @param WetellSourcePort $portal Quelle.
     * @param InvoiceLoggerPort $logger Logging.
     */
    public function __construct(
        private WetellSourcePort $portal,
        private InvoiceLoggerPort $logger
    ) {
    }

    /**
     * @param string $runId    Lauf-ID.
     * @param string $username Nutzer.
     * @param string $password Passwort.
     * @return list<SourceInvoice> gefundene Rechnungen.
     */
    public function execute(string $runId, string $username, string $password): array
    {
        $this->logger->logStep($runId, 'discover', 'START', ['step' => 'login']);
        $this->portal->login($username, $password);

        $this->logger->logStep($runId, 'discover', 'START', ['step' => 'list']);
        $list = $this->portal->discoverInvoices();
        $this->logger->logStep($runId, 'discover', 'DONE', ['count' => count($list)]);

        return array_values(array_filter($list, static function (SourceInvoice $invoice): bool {
            return trim($invoice->sourceId) !== '';
        }));
    }
}