<?php

namespace App\Entity;

use App\Repository\SnipContentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;

#[ORM\Entity(repositoryClass: SnipContentRepository::class)]
class SnipContent
{
    #[ORM\Id]
    #[ORM\Column(type: UlidType::NAME, unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')]
    public ?Ulid $id = null;

    #[ORM\ManyToOne(inversedBy: 'snipContents')]
    #[ORM\JoinColumn(nullable: false)]
    public ?Snip $snip = null;

    #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
    public ?self $parent = null;

    /** @var Collection<int, self> */
    #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
    public Collection $children;

    #[ORM\Column(type: Types::TEXT, nullable: true)]
    public ?string $text = null;

    #[ORM\Column(nullable: true)]
    public ?array $diff = null;

    #[ORM\Column(length: 255, nullable: true)]
    public ?string $name = null;

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