<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class ServiceLog
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: Service::class)]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private Service $service;

    #[ORM\Column(length: 20)]
    private string $fromStatus;

    #[ORM\Column(length: 20)]
    private string $toStatus;

    #[ORM\Column(length: 50)]
    private string $source = 'manual';

    #[ORM\ManyToOne(targetEntity: User::class)]
    #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
    private ?User $changedBy = null;

    #[ORM\Column]
    private \DateTimeImmutable $createdAt;

    public function __construct(Service $service, string $fromStatus, string $toStatus, string $source = 'manual', ?User $changedBy = null)
    {
        $this->service = $service;
        $this->fromStatus = $fromStatus;
        $this->toStatus = $toStatus;
        $this->source = $source;
        $this->changedBy = $changedBy;
        $this->createdAt = new \DateTimeImmutable();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getService(): Service
    {
        return $this->service;
    }

    public function getFromStatus(): string
    {
        return $this->fromStatus;
    }

    public function getToStatus(): string
    {
        return $this->toStatus;
    }

    public function getSource(): string
    {
        return $this->source;
    }

    public function getChangedBy(): ?User
    {
        return $this->changedBy;
    }

    public function getCreatedAt(): \DateTimeImmutable
    {
        return $this->createdAt;
    }
}
