<?php

namespace App\Entity\Helpers;

use App\Entity\User;
use DateTime;
use Doctrine\ORM\Mapping as ORM;

trait TrackedTrait
{
    #[ORM\Column]
    #[ORM\JoinColumn(nullable: false)]
    public ?DateTime $createdAt = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false)]
    public ?User $createdBy = null;

    public function setCreatedAtNowNoSeconds(): self
    {
        $this->createdAt = DateTime::createFromFormat('Y-m-d H:i', date('Y-m-d H:i'));

        return $this;
    }

    public function setCreatedAtNow(): self
    {
        $this->createdAt = new DateTime();

        return $this;
    }
}
