<?php

namespace App\Tests\Entity;

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

class AuditLogTest extends TestCase
{
    public function testConstructor(): void
    {
        $log = new AuditLog('order_created', 'BilletBuyer', 42);

        self::assertNull($log->getId());
        self::assertSame('order_created', $log->getAction());
        self::assertSame('BilletBuyer', $log->getEntityType());
        self::assertSame(42, $log->getEntityId());
        self::assertSame([], $log->getData());
        self::assertNull($log->getPerformedBy());
        self::assertNull($log->getIpAddress());
        self::assertInstanceOf(\DateTimeImmutable::class, $log->getCreatedAt());
    }

    public function testSetData(): void
    {
        $log = new AuditLog('test', 'Entity');
        $result = $log->setData(['key' => 'value']);

        self::assertSame(['key' => 'value'], $log->getData());
        self::assertSame($log, $result);
    }

    public function testSetPerformedBy(): void
    {
        $log = new AuditLog('test', 'Entity');
        $result = $log->setPerformedBy('admin@test.fr');

        self::assertSame('admin@test.fr', $log->getPerformedBy());
        self::assertSame($log, $result);
    }

    public function testSetIpAddress(): void
    {
        $log = new AuditLog('test', 'Entity');
        $result = $log->setIpAddress('127.0.0.1');

        self::assertSame('127.0.0.1', $log->getIpAddress());
        self::assertSame($log, $result);
    }
}
