<?php

namespace App\Tests\Service\Pdf;

use App\Entity\Contrats;
use App\Entity\ContratsPayments;
use App\Entity\Customer;
use App\Service\Pdf\PlPdf;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\KernelInterface;

class PlPdfTest extends TestCase
{
    public function testGenerate(): void
    {
        $kernel = $this->createStub(KernelInterface::class);
        $kernel->method('getProjectDir')->willReturn(sys_get_temp_dir());

        // Create dummy favicon for logo check
        $faviconDir = sys_get_temp_dir() . '/public/provider/images';
        if (!is_dir($faviconDir)) {
            mkdir($faviconDir, 0777, true);
        }
        $pngData = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
        file_put_contents($faviconDir . '/favicon.png', $pngData);

        $contrat = $this->createStub(Contrats::class);
        $contratsPayments = $this->createStub(ContratsPayments::class);
        $customer = $this->createStub(Customer::class);

        $contrat->method('getNumReservation')->willReturn('RES-123');
        $contrat->method('getCustomer')->willReturn($customer);

        $customer->method('getSurname')->willReturn('John');
        $customer->method('getName')->willReturn('Doe');
        $customer->method('getEmail')->willReturn('john@example.com');

        $contratsPayments->method('getAmount')->willReturn(100.0);
        $contratsPayments->method('getValidateAt')->willReturn(new \DateTimeImmutable('2023-01-01 12:00:00'));
        $contratsPayments->method('getCard')->willReturn(['type' => 'Carte Bancaire']);
        $contratsPayments->method('getPaymentId')->willReturn('TX-999');

        $pdfService = new PlPdf($kernel, $contratsPayments, $contrat);
        $content = $pdfService->generate();

        $this->assertNotEmpty($content);
        $this->assertStringStartsWith('%PDF', $content);
    }
}
