<?php
declare(strict_types=1);

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use App\Enum\SectorStatusEnum;
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 Sector
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

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

    /** @var Collection<int, System> */
    #[ORM\OneToMany(targetEntity: System::class, mappedBy: 'sector', orphanRemoval: true)]
    private Collection $systems;

    #[ORM\ManyToOne(targetEntity: Galaxy::class, inversedBy: 'sectors')]
    #[ORM\JoinColumn(nullable: true)]
    private ?Galaxy $galaxy = null;

    #[ORM\Column(length: 24, enumType: SectorStatusEnum::class, options: ['default' => SectorStatusEnum::UNEXPLORED])]
    private SectorStatusEnum $status = SectorStatusEnum::UNEXPLORED;

    public function __construct()
    {
        $this->systems = new ArrayCollection();
    }

    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 getSystems(): Collection
    {
        return $this->systems;
    }

    public function setSystems(Collection $systems): self
    {
        $this->systems = $systems;
        return $this;
    }

    public function addSystem(System $system): self
    {
        if (!$this->systems->contains($system)) {
            $this->systems->add($system);
            $system->setSector($this);
        }
        return $this;
    }

    public function removeSystem(System $system): self
    {
        if ($this->systems->removeElement($system)) {
            if ($system->getSector() === $this) {
                $system->setSector(null);
            }
        }
        return $this;
    }

    public function getGalaxy(): ?Galaxy
    {
        return $this->galaxy;
    }

    public function setGalaxy(?Galaxy $galaxy): self
    {
        $this->galaxy = $galaxy;
        if ($galaxy && !$galaxy->getSectors()->contains($this)) {
            $galaxy->addSector($this);
        }
        return $this;
    }

    public function getStatus(): SectorStatusEnum
    {
        return $this->status;
    }

    public function setStatus(SectorStatusEnum $status): self
    {
        $this->status = $status;
        return $this;
    }
}