<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\MainBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;

#[ORM\Entity]
#[ORM\Table(name: 'chill_main_geographical_unit_layer')]
#[ORM\UniqueConstraint(name: 'geographical_unit_layer_refid', columns: ['refId'])]
class GeographicalUnitLayer
{
    #[Serializer\Groups(['read'])]
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)]
    private ?int $id = null;

    #[Serializer\Groups(['read'])]
    #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]'])]
    private array $name = [];

    #[Serializer\Groups(['read'])]
    #[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])]
    private string $refId = '';

    /**
     * @var Collection<int, GeographicalUnit>
     */
    #[ORM\OneToMany(mappedBy: 'layer', targetEntity: GeographicalUnit::class)]
    private Collection $units;

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

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

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

    public function getRefId(): string
    {
        return $this->refId;
    }

    public function getUnits(): Collection
    {
        return $this->units;
    }

    public function setName(array $name): GeographicalUnitLayer
    {
        $this->name = $name;

        return $this;
    }
}
