<?php

namespace AppBundle\Entity\Traits;

use Doctrine\ORM\Mapping as ORM;
use Dunglas\ApiBundle\Annotation\Iri;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @Iri("http://schema.org/Generic")
 */
trait TimestampableEntity
{
    /**
     * @var \DateTime
     *
     * @Gedmo\Timestampable(on="create")
     */
    #[ORM\Column(type: 'datetime', nullable: true)]
    #[Assert\Date]
    #[Groups(['timestampable', 'template_list', 'notification_list', 'education_student_wish_list', 'email_detail', 'access_files_person', 'messagesend_list', 'online_registration_access_family_accesswishes'])]
    private $createDate;

    /**
     * @var \DateTime
     *
     * @Gedmo\Timestampable(on="update")
     */
    #[ORM\Column(type: 'datetime', nullable: true)]
    #[Assert\Date]
    #[Groups(['timestampable', 'education_student_next_year', 'education_student_wish_list'])]
    private $updateDate;

    /**
     * Sets createDate.
     *
     * @param \DateTime $createDate
     *
     * @return $this
     */
    public function setCreateDate(\DateTime $createDate = null)
    {
        $this->createDate = $createDate;

        return $this;
    }

    /**
     * Gets createDate.
     *
     * @return \DateTime
     */
    public function getCreateDate()
    {
        return $this->createDate;
    }

    /**
     * Sets updateDate.
     *
     * @param \DateTime $updateDate
     *
     * @return $this
     */
    public function setUpdateDate(\DateTime $updateDate = null)
    {
        $this->updateDate = $updateDate;

        return $this;
    }

    /**
     * Gets updateDate.
     *
     * @return \DateTime
     */
    public function getUpdateDate()
    {
        return $this->updateDate ? $this->updateDate->format('Y-m-d') : $this->updateDate;
    }
}
