<?php

namespace App\DoctorService\Entity;

use App\DoctorService\Repository\DoctorServiceRepository;
use App\Specialty\Entity\Specialty;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: DoctorServiceRepository::class)]
#[ORM\Table(name: 'doctor_services')]
#[ORM\UniqueConstraint(name: 'uq_doctor_services_slug', columns: ['slug'])]
#[ORM\Index(columns: ['status'], name: 'idx_doctor_services_status')]
#[ORM\Index(columns: ['specialty_id'], name: 'idx_doctor_services_specialty')]
class DoctorService
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 36, unique: true)]
    private string $uuid;

    #[ORM\Column(type: 'string', length: 255)]
    private string $name;

    #[ORM\Column(type: 'string', length: 255, unique: true)]
    private string $slug;

    #[ORM\Column(type: 'smallint')]
    private int $status = 1;

    #[ORM\Column(type: 'integer')]
    private int $weight = 0;

    #[ORM\ManyToOne(targetEntity: Specialty::class)]
    #[ORM\JoinColumn(name: 'specialty_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?Specialty $specialty = null;

    public function __construct(string $name, string $slug, ?Specialty $specialty = null)
    {
        $this->uuid      = Uuid::v4()->toRfc4122();
        $this->name      = $name;
        $this->slug      = $slug;
        $this->specialty = $specialty;
    }

    public function getId(): ?int          { return $this->id; }
    public function getUuid(): string      { return $this->uuid; }
    public function getName(): string      { return $this->name; }
    public function getSlug(): string      { return $this->slug; }
    public function getStatus(): int       { return $this->status; }
    public function getWeight(): int       { return $this->weight; }
    public function getSpecialty(): ?Specialty { return $this->specialty; }

    public function setName(string $v): self       { $this->name = $v; return $this; }
    public function setSlug(string $v): self       { $this->slug = $v; return $this; }
    public function setStatus(int $v): self        { $this->status = $v; return $this; }
    public function setWeight(int $v): self        { $this->weight = $v; return $this; }
    public function setSpecialty(?Specialty $v): self { $this->specialty = $v; return $this; }

    public function toArray(): array
    {
        return [
            'id'           => $this->id,
            'uuid'         => $this->uuid,
            'name'         => $this->name,
            'slug'         => $this->slug,
            'status'       => $this->status,
            'weight'       => $this->weight,
            'specialty_id' => $this->specialty?->getId(),
        ];
    }
}
