<?php

namespace App\Entity;

use App\RecordInterface;
use App\Repository\BibliographyRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use App\RecordStatus;
use ContainerBNNizmi\getBibliographyRepositoryService;
use Doctrine\Common\Collections\Collection as DoctrineCollection;
use Doctrine\DBAL\Query\QueryBuilder as QueryQueryBuilder;
use Doctrine\ORM\QueryBuilder;

#[ORM\Entity(repositoryClass: BibliographyRepository::class)]
#[ORM\Table(name: 'bibliography')]
class Bibliography implements RecordInterface
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(name: 'id')]
    private ?int $id = null;

    #[ORM\Column(name: 'stato')]
    private ?int $status = null;

    #[ORM\Column(name: 'modif')]
    private ?DateTimeImmutable $modifiedAt = null;

    #[ORM\Column(name: 'cit_bib', type: Types::TEXT)]
    private ?string $citation = null;

    #[ORM\Column(name: 'rif_bib', type: Types::TEXT)]
    private ?string $reference = null;

    #[ORM\Column(name: 'resp', length: 100)]
    private ?string $owner = null;

    #[ORM\Column(name: 'note_bib', type: Types::TEXT)]
    private ?string $notes = null;

    #[ORM\Column(length: 100, name: 'editor')]
    private ?string $editor = null;

    #[ORM\Column(length: 100, name: 'creator')]
    private ?string $creator = null;

    #[ORM\JoinTable(name: 'rel_riferimento_collezione')]
    #[ORM\JoinColumn(name: 'Bibliografia_id_bib', referencedColumnName: 'id')]
    #[ORM\InverseJoinColumn(name: 'Collezione_id_coll', referencedColumnName: 'id')]
    #[ORM\ManyToMany(targetEntity: Collection::class, inversedBy: 'bibliography')]
    private DoctrineCollection $collections;

    private DoctrineCollection $documents;

    private DoctrineCollection $objects;

    #[ORM\JoinTable(name: 'rel_riferimento_personaggio')]
    #[ORM\JoinColumn(name: 'Bibliografia_id_bib', referencedColumnName: 'id')]
    #[ORM\InverseJoinColumn(name: 'Personaggio_id_pers', referencedColumnName: 'id')]
    #[ORM\ManyToMany(targetEntity: Collector::class, inversedBy: 'bibliography')]
    private DoctrineCollection $collectors;

    private DoctrineCollection $sites;

    // Checks if the record can be edited by an 'editor' user
    private bool $isEditable = false;

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

    public function getStatus(): ?string
    {
        $status = RecordStatus::tryFrom($this->status);
        return $status->toString();
    }

    public function setStatus(int $status): static
    {
        $this->status = $status;

        return $this;
    }

    public function getModifiedAt(): ?DateTimeImmutable
    {
        return $this->modifiedAt;
    }

    public function setModifiedAt(DateTimeImmutable $modifiedAt): static
    {
        $this->modifiedAt = $modifiedAt;

        return $this;
    }

    public function getOwner(): ?string
    {
        return $this->owner;
    }

    public function setOwner(string $owner): static
    {
        $this->owner = $owner;

        return $this;
    }

    public function getEditor(): ?string
    {
        return $this->editor;
    }

    public function setEditor(string $editor): static
    {
        $this->editor = $editor;

        return $this;
    }

    public function getCreator(): ?string
    {
        return $this->creator;
    }

    public function setCreator(string $creator): static
    {
        $this->creator = $creator;

        return $this;
    }

    public function getCitation(): ?string
    {
        return $this->citation;
    }

    public function setCitation(string $citation): static
    {
        $this->citation = $citation;

        return $this;
    }

    public function getReference(): ?string
    {
        return $this->reference;
    }

    public function setReference(string $reference): static
    {
        $this->reference = $reference;

        return $this;
    }

    public function getNotes(): ?string
    {
        return $this->notes;
    }

    public function setNotes(string $notes): static
    {
        $this->notes = $notes;

        return $this;
    }

    public function getCollections(): ?DoctrineCollection
    {
        return $this->collections;
    }

    public function setCollections(DoctrineCollection $collections): static
    {
        $this->collections = $collections;

        return $this;
    }

    public function getCollectors(): ?DoctrineCollection
    {
        return $this->collectors;
    }

    public function setCollectors(DoctrineCollection $collectors): static
    {
        $this->collectors = $collectors;

        return $this;
    }

    public function getEditableStatus(): bool
    {
        return $this->isEditable;
    }

    public function setEditableStatus(bool $status): static
    {
        $this->isEditable = $status;
        
        return $this;
    }
}
