<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\Entity;

use Ferienpass\CoreBundle\Entity\PmPaymentTransactionStatus;
use PHPUnit\Framework\TestCase;

final class PmPaymentTransactionStatusTest extends TestCase
{
    public function testGetIdIsNullByDefault(): void
    {
        self::assertNull($this->createStatus()->getId());
    }

    public function testGetTxidReturnsTxid(): void
    {
        self::assertSame('TX-001', $this->createStatus()->getTxid());
    }

    public function testGetStatusReturnsStatus(): void
    {
        self::assertSame(1, $this->createStatus()->getStatus());
    }

    public function testGetDescriptionReturnsDescription(): void
    {
        self::assertSame('Success', $this->createStatus()->getDescription());
    }

    public function testGetPayloadReturnsPayload(): void
    {
        self::assertSame(['amount' => 100], $this->createStatus()->getPayload());
    }

    public function testGetCreatedAtReturnsCreatedAt(): void
    {
        $status = $this->createStatus();

        self::assertSame('2024-01-01', $status->getCreatedAt()->format('Y-m-d'));
    }

    public function testGetModifiedAtReturnsModifiedAt(): void
    {
        $status = $this->createStatus();

        self::assertSame('2024-01-02', $status->getModifiedAt()->format('Y-m-d'));
    }

    public function testSetStatusUpdatesStatus(): void
    {
        $status = $this->createStatus();
        $status->setStatus(0);

        self::assertSame(0, $status->getStatus());
    }

    public function testSetDescriptionUpdatesDescription(): void
    {
        $status = $this->createStatus();
        $status->setDescription('Failed');

        self::assertSame('Failed', $status->getDescription());
    }

    public function testSetCreatedAtUpdatesCreatedAt(): void
    {
        $status = $this->createStatus();
        $ts = new \DateTimeImmutable('2025-03-01');
        $status->setCreatedAt($ts);

        self::assertSame($ts, $status->getCreatedAt());
    }

    public function testSetModifiedAtUpdatesModifiedAt(): void
    {
        $status = $this->createStatus();
        $ts = new \DateTimeImmutable('2025-03-02');
        $status->setModifiedAt($ts);

        self::assertSame($ts, $status->getModifiedAt());
    }

    public function testSetPayloadUpdatesPayload(): void
    {
        $status = $this->createStatus();
        $status->setPayload(['new' => 'data']);

        self::assertSame(['new' => 'data'], $status->getPayload());
    }

    public function testNullableFields(): void
    {
        $status = new PmPaymentTransactionStatus('TX-null', 0, null, null, null, []);

        self::assertNull($status->getDescription());
        self::assertNull($status->getCreatedAt());
        self::assertNull($status->getModifiedAt());
    }

    private function createStatus(): PmPaymentTransactionStatus
    {
        return new PmPaymentTransactionStatus(
            'TX-001',
            1,
            'Success',
            new \DateTimeImmutable('2024-01-01'),
            new \DateTimeImmutable('2024-01-02'),
            ['amount' => 100]
        );
    }
}
