<?php
declare (strict_types=1);

namespace App\Entity\Organization;

use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\Organization\OrganizationArticleRepository;

//use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\ORM\Mapping as ORM;

/**
 * Fait le lien entre une Organization et un coup de projecteur
 */
#[ApiResource(
    operations: [
        new Get(
            security: 'is_granted("ROLE_ORGANIZATION_VIEW" and object.getOrganization().getId() == user.getOrganization().getId()'
        ),
        new GetCollection(
            security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\')'
        )
    ],
    security: 'is_granted(\'ROLE_ORGANIZATION\')'
)]
//#[Auditable]
#[ORM\Entity(repositoryClass: OrganizationArticleRepository::class)]
class OrganizationArticle
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'organizationArticles')]
    #[ORM\JoinColumn(nullable: true)]
    private Organization $organization;

    #[ORM\Column(length: 255)]
    private string $title;

    #[ORM\Column(length: 255)]
    private string $link;

    #[ORM\Column(type: 'date', nullable: true)]
    private ?\DateTimeInterface $date = null;

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

    public function getOrganization(): ?Organization
    {
        return $this->organization;
    }

    public function setOrganization(?Organization $organization): self
    {
        $this->organization = $organization;
        return $this;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(?string $title): self
    {
        $this->title = $title;
        return $this;
    }

    public function getLink(): ?string
    {
        return $this->link;
    }

    public function setLink(?string $link): self
    {
        $this->link = $link;
        return $this;
    }

    public function getDate(): ?\DateTimeInterface
    {
        return $this->date;
    }

    public function setDate(?\DateTime $date = null): self
    {
        $this->date = $date;
        return $this;
    }
}
