<?php

namespace App\Tests\Entity;

use App\Entity\Service;
use App\Entity\ServiceCategory;
use App\Entity\ServiceLog;
use App\Entity\User;
use PHPUnit\Framework\TestCase;

class ServiceLogTest extends TestCase
{
    private function createService(): Service
    {
        return new Service('Esy-Web', 'esy-web', new ServiceCategory('Web', 'web'));
    }

    public function testConstructorDefaults(): void
    {
        $service = $this->createService();
        $log = new ServiceLog($service, 'up', 'down');

        $this->assertNull($log->getId());
        $this->assertSame($service, $log->getService());
        $this->assertSame('up', $log->getFromStatus());
        $this->assertSame('down', $log->getToStatus());
        $this->assertSame('manual', $log->getSource());
        $this->assertNull($log->getChangedBy());
        $this->assertInstanceOf(\DateTimeImmutable::class, $log->getCreatedAt());
    }

    public function testConstructorWithSourceAndUser(): void
    {
        $service = $this->createService();
        $user = new User();
        $user->setEmail('admin@test.com');
        $user->setFirstName('A');
        $user->setLastName('B');
        $user->setPassword('h');

        $log = new ServiceLog($service, 'down', 'up', 'cron', $user);

        $this->assertSame('cron', $log->getSource());
        $this->assertSame($user, $log->getChangedBy());
    }
}
