<?php

namespace App\Tests\Entity;

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

class MessengerLogTest extends TestCase
{
    public function testConstructorSetsFields(): void
    {
        $log = new MessengerLog(
            messageClass: 'App\\Message\\TestMessage',
            messageBody: 'serialized-body',
            errorMessage: 'Something failed',
            stackTrace: '#0 trace',
            transportName: 'async',
            retryCount: 2,
        );

        self::assertSame('App\\Message\\TestMessage', $log->getMessageClass());
        self::assertSame('serialized-body', $log->getMessageBody());
        self::assertSame('failed', $log->getStatus());
        self::assertSame('Something failed', $log->getErrorMessage());
        self::assertSame('#0 trace', $log->getStackTrace());
        self::assertSame('async', $log->getTransportName());
        self::assertSame(2, $log->getRetryCount());
        self::assertInstanceOf(\DateTimeImmutable::class, $log->getCreatedAt());
        self::assertInstanceOf(\DateTimeImmutable::class, $log->getFailedAt());
        self::assertNull($log->getId());
    }

    public function testMarkAsResolved(): void
    {
        $log = new MessengerLog('Class', null, 'error');
        $log->markAsResolved();

        self::assertSame('resolved', $log->getStatus());
    }

    public function testSetStatus(): void
    {
        $log = new MessengerLog('Class', null, 'error');
        $result = $log->setStatus('retrying');

        self::assertSame('retrying', $log->getStatus());
        self::assertSame($log, $result);
    }
}
