<?php

namespace App\Entity;

use App\Repository\RecordRepository;
use Doctrine\ORM\Mapping as ORM;
use App\Bundle\Crypt\AES;

/**
 * @ORM\Entity(repositoryClass=RecordRepository::class)
 */
class Record
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="integer")
     */
    private $specialistId;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $phone;

    /**
     * @ORM\Column(type="datetime")
     */
    private $createAt;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $hash;

    /**
     * @ORM\Column(type="array")
     */
    private $reserve = [];

    /**
     * @ORM\OneToOne(targetEntity=AlertSms::class, mappedBy="record", cascade={"persist", "remove"})
     */
    private $alertSms;

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

    public function getSpecialistId(): ?int
    {
        return $this->specialistId;
    }

    public function setSpecialistId(int $specialistId): self
    {
        $this->specialistId = $specialistId;

        return $this;
    }

    public function getPhone(): ?string
    {
        return !empty($this->phone)? AES::decrypt($this->phone): $this->phone;
    }

    public function setPhone(string $phone): self
    {
        $this->phone = AES::encrypt($phone);

        return $this;
    }

    public function getCreateAt(): ?\DateTimeInterface
    {
        return $this->createAt;
    }

    public function setCreateAt(\DateTimeInterface $createAt): self
    {
        $this->createAt = $createAt;

        return $this;
    }

    public function getHash(): ?string
    {
        return $this->hash;
    }

    public function setHash(string $hash): self
    {
        $this->hash = md5($hash);

        return $this;
    }

    public function getReserve(): ?array
    {
        return $this->reserve;
    }

    public function setReserve(array $reserve): self
    {
        $this->reserve = $reserve;

        return $this;
    }

    public function getAlertSms(): ?AlertSms
    {
        return $this->alertSms;
    }

    public function setAlertSms(?AlertSms $alertSms): self
    {
        // unset the owning side of the relation if necessary
        if ($alertSms === null && $this->alertSms !== null) {
            $this->alertSms->setRecord(null);
        }

        // set the owning side of the relation if necessary
        if ($alertSms !== null && $alertSms->getRecord() !== $this) {
            $alertSms->setRecord($this);
        }

        $this->alertSms = $alertSms;

        return $this;
    }
}
