<?php

namespace Tests\Feature;

use App\Mail\MissingSongRequest;
use Illuminate\Support\Facades\Route;
use Tests\TestCase;

class MissingSongMailTest extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        // Register a test route for services.edit
        Route::get('/services/{id}/edit', function ($id) {
            return "Service {$id}";
        })->name('services.edit');
    }

    public function test_missing_song_request_mailable_renders_with_german_content(): void
    {
        $songName = 'Großer Gott';
        $ccliId = '12345678';
        $serviceId = 1;
        $serviceTitle = 'Sonntagsgottesdienst';
        $serviceDate = '2026-03-08';

        // Create a mock service object
        $service = new \stdClass;
        $service->id = $serviceId;
        $service->title = $serviceTitle;
        $service->date = $serviceDate;

        $mailable = new MissingSongRequest($songName, $ccliId, $service);

        // Assert the mailable renders without errors
        $rendered = $mailable->render();
        $subject = $mailable->build()->subject;
        $rendered = $mailable->render();

        // Check that the rendered content contains German text
        $this->assertStringContainsString('Song-Anfrage', $subject);
        $this->assertStringContainsString($songName, $rendered);
        $this->assertStringContainsString($ccliId, $rendered);
        $this->assertStringContainsString($serviceTitle, $rendered);
        $this->assertStringContainsString('wird folgender Song benötigt', $rendered);
        $this->assertStringContainsString('Bitte erstelle diesen Song', $rendered);
        $this->assertStringContainsString('/services/1/edit', $rendered);
    }

    public function test_missing_song_request_mailable_has_correct_subject(): void
    {
        $songName = 'Großer Gott';
        $ccliId = '12345678';

        $service = new \stdClass;
        $service->id = 1;
        $service->title = 'Sonntagsgottesdienst';
        $service->date = '2026-03-08';

        $mailable = new MissingSongRequest($songName, $ccliId, $service);

        // Get the subject from the mailable
        $subject = $mailable->build()->subject;

        $this->assertStringContainsString('Song-Anfrage', $subject);
        $this->assertStringContainsString($songName, $subject);
        $this->assertStringContainsString($ccliId, $subject);
    }
}
