<?php

namespace App\Tests\Entity;

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

class DocusealEventTest extends TestCase
{
    public function testConstructorMinimalArgs(): void
    {
        $event = new DocusealEvent('submission', 'completed');

        $this->assertNull($event->getId());
        $this->assertSame('submission', $event->getType());
        $this->assertSame('completed', $event->getEventType());
        $this->assertNull($event->getSubmissionId());
        $this->assertNull($event->getSubmitterId());
        $this->assertNull($event->getPayload());
        $this->assertInstanceOf(\DateTimeImmutable::class, $event->getCreatedAt());
    }

    public function testConstructorWithAllArgs(): void
    {
        $payload = '{"submission_id":42,"submitter_id":7,"status":"completed"}';
        $event = new DocusealEvent('submitter', 'opened', 42, 7, $payload);

        $this->assertSame('submitter', $event->getType());
        $this->assertSame('opened', $event->getEventType());
        $this->assertSame(42, $event->getSubmissionId());
        $this->assertSame(7, $event->getSubmitterId());
        $this->assertSame($payload, $event->getPayload());
    }

    public function testSubmissionIdNullable(): void
    {
        $event = new DocusealEvent('submission', 'completed', null, null);
        $this->assertNull($event->getSubmissionId());
    }

    public function testSubmitterIdNullable(): void
    {
        $event = new DocusealEvent('submission', 'completed', 10, null);
        $this->assertSame(10, $event->getSubmissionId());
        $this->assertNull($event->getSubmitterId());
    }

    public function testPayloadNullable(): void
    {
        $event = new DocusealEvent('submission', 'completed', 1, 2, null);
        $this->assertNull($event->getPayload());
    }

    public function testCreatedAtTimestamp(): void
    {
        $before = new \DateTimeImmutable();
        $event = new DocusealEvent('submission', 'completed');
        $after = new \DateTimeImmutable();

        $this->assertGreaterThanOrEqual($before, $event->getCreatedAt());
        $this->assertLessThanOrEqual($after, $event->getCreatedAt());
    }

    public function testTypesAreImmutableAfterConstruction(): void
    {
        $event = new DocusealEvent('form', 'signed', 100, 200, '{}');

        // Getters must return exactly what was passed in
        $this->assertSame('form', $event->getType());
        $this->assertSame('signed', $event->getEventType());
        $this->assertSame(100, $event->getSubmissionId());
        $this->assertSame(200, $event->getSubmitterId());
        $this->assertSame('{}', $event->getPayload());
    }
}
