<?php

namespace Tests\Unit;

use App\EventPaymentModules\DTO\RegistrationSummaryRequest;
use App\EventPaymentModules\Modules\UndefinedPaymentModule;
use App\Models\EventParticipant;
use App\ValueObjects\Amount;
use PHPUnit\Framework\TestCase;

/**
 * Reine Modul-Logik ohne Framework-Kontext. Das Überweisungs-Modul rendert inzwischen Blade und wird
 * daher auf Feature-Ebene getestet (siehe EventParticipantPaymentSummaryTest).
 */
class RegistrationSummaryTest extends TestCase
{
    private function participant(float $amount, float $amountPaid, string $purpose = 'Zweck'): EventParticipant
    {
        $participant = new EventParticipant();
        $participant->setRawAttributes([
            'payment_purpose' => $purpose,
        ], true);
        // Amount-Casts umgehen und die Value-Objects direkt setzen.
        $participant->amount = new Amount($amount, ' Euro');
        $participant->amount_paid = new Amount($amountPaid, ' Euro');

        return $participant;
    }

    public function test_cash_summary_empty_when_no_text_configured(): void
    {
        $module = new UndefinedPaymentModule();
        $summary = $module->registrationSummary(new RegistrationSummaryRequest(
            $this->participant(50.0, 0.0),
            [],
        ));

        $this->assertFalse($summary->hasPaymentInformation);
    }

    public function test_cash_module_requires_payment_information_option(): void
    {
        $module = new UndefinedPaymentModule();

        $this->assertSame(['payment_information'], $module->requiredOptionKeys());
        $this->assertFalse($module->isConfigurationComplete([]));
        $this->assertTrue($module->isConfigurationComplete(['payment_information' => '<p>Text</p>']));
    }
}
