<?php
declare(strict_types=1);

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use App\Enum\CelestialBodySizeEnum;
use App\Enum\PlanetTypeEnum;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;


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

    #[ORM\Column(length: 100, nullable: false)]
    private string $name;

    #[ORM\ManyToOne(targetEntity: System::class, inversedBy: 'planets')]
    #[ORM\JoinColumn(nullable: true)]
    private ?System $system = null;

    #[ORM\Column(length: 24, enumType: PlanetTypeEnum::class, options: ['default' => PlanetTypeEnum::UNINHABITABLE])]
    private PlanetTypeEnum $type;

    #[ORM\Column(nullable: true)]
    #[Assert\Range(notInRangeMessage: 'between_{{ min }}_and_{{ max }}', min: 1, max: 7)]
    private ?int $position = null;

    #[ORM\Column(length: 3, enumType: CelestialBodySizeEnum::class, options: ['default' => CelestialBodySizeEnum::M])]
    private CelestialBodySizeEnum $size = CelestialBodySizeEnum::M;

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

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

    public function getName(): string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;
        return $this;
    }

    public function getSystem(): ?System
    {
        return $this->system;
    }

    public function setSystem(?System $system): self
    {
        $this->system = $system;
        if ($system && !$system->getPlanets()->contains($this)) {
            $system->addPlanet($this);
        }
        return $this;
    }

    public function getType(): PlanetTypeEnum
    {
        return $this->type;
    }

    public function setType(PlanetTypeEnum $type): self
    {
        $this->type = $type;
        return $this;
    }

    public function getPosition(): ?int
    {
        return $this->position;
    }

    public function setPosition(?int $position): self
    {
        $this->position = $position;
        return $this;
    }

    public function getSize(): CelestialBodySizeEnum
    {
        return $this->size;
    }

    public function setSize(CelestialBodySizeEnum $size): self
    {
        $this->size = $size;
        return $this;
    }
}