<?php

namespace App\Tests\Entity;

use App\Entity\MessengerLog;
use PHPUnit\Framework\TestCase;

class MessengerLogTest extends TestCase
{
    public function testConstructor(): void
    {
        $log = new MessengerLog('App\Message\TestMessage', '{"data":"test"}', 'Error occurred', 'stack trace', 'async', 2);
        $this->assertNull($log->getId());
        $this->assertSame('App\Message\TestMessage', $log->getMessageClass());
        $this->assertSame('{"data":"test"}', $log->getMessageBody());
        $this->assertSame('failed', $log->getStatus());
        $this->assertSame('Error occurred', $log->getErrorMessage());
        $this->assertSame('stack trace', $log->getStackTrace());
        $this->assertSame('async', $log->getTransportName());
        $this->assertSame(2, $log->getRetryCount());
        $this->assertInstanceOf(\DateTimeImmutable::class, $log->getCreatedAt());
        $this->assertInstanceOf(\DateTimeImmutable::class, $log->getFailedAt());
    }

    public function testConstructorMinimal(): void
    {
        $log = new MessengerLog('App\Message\Test', null, 'Error');
        $this->assertNull($log->getMessageBody());
        $this->assertNull($log->getStackTrace());
        $this->assertNull($log->getTransportName());
        $this->assertSame(0, $log->getRetryCount());
    }

    public function testSetStatus(): void
    {
        $log = new MessengerLog('App\Message\Test', null, 'Error');
        $this->assertSame('failed', $log->getStatus());
        $log->setStatus('resolved');
        $this->assertSame('resolved', $log->getStatus());
    }

    public function testMarkAsResolved(): void
    {
        $log = new MessengerLog('App\Message\Test', null, 'Error');
        $log->markAsResolved();
        $this->assertSame('resolved', $log->getStatus());
    }
}
