<?php 
namespace App\Entity; 
 
use ApiPlatform\Metadata\ApiResource; 
use ApiPlatform\Metadata\Get; 
use ApiPlatform\Metadata\GetCollection; 
use App\Controller\Action\StatusWithEvaluationStatAction; 
use Symfony\Component\Serializer\Annotation\Groups; 
use Doctrine\Common\Collections\Collection; 
use Doctrine\ORM\Mapping as ORM; 
use ApiPlatform\Metadata\Post; 
 
#[ApiResource( 
    operations: [ 
        new GetCollection(), 
        new Post( 
            uriTemplate: '/evaluation_statuses/with_stat', 
            controller: StatusWithEvaluationStatAction::class, 
            read: false, 
            write: false, 
            name: '_api_/evaluation_statuses/with_stat' 
        ), 
        new Get(), 
    ], 
    normalizationContext: ['groups' => ['compliance.get', 'evaluation.get', 'compliance:evaluation:get']] 
)] 
#[ORM\Entity] 
class EvaluationStatus 
{ 
    #[ORM\Column(name: 'id', type: 'integer', nullable: false)] 
    #[ORM\Id] 
    #[Groups(['compliance.get', 'evaluation.get', 'compliance:evaluation:get','plan.get'])] 
    private int $id;   
 
    #[ORM\Column(nullable: true)] 
    #[Groups(['compliance.get', 'evaluation.get', 'compliance:evaluation:get','plan.get'])] 
    private string $name; 
 
    #[ORM\OneToMany(mappedBy: 'status', targetEntity: Evaluation::class)] 
    private Collection $evaluations; 
 
    #[ORM\Column(length: 255)] 
    #[Groups(['compliance.get', 'evaluation.get', 'compliance:evaluation:get','plan.get'])] 
    private ?string $color = null; 
 
    public function getId():int 
    { 
        return $this->id; 
    } 
 
    public function setId(int $id) 
    { 
        $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 getEvaluations(): Collection 
    { 
        return $this->evaluations; 
    } 
 
    public function addEvaluation(Evaluation $evaluation): self 
    { 
        if (!$this->evaluations->contains($evaluation)) { 
            $this->evaluations->add($evaluation); 
            $evaluation->setStatus($this); 
        } 
 
        return $this; 
    } 
 
    public function removeEvaluation(Evaluation $evaluation): self 
    { 
        if ($this->evaluations->removeElement($evaluation)) { 
            // set the owning side to null (unless already changed) 
            if ($evaluation->getDocument() === $this) { 
                $evaluation->setStatus(null); 
            } 
        } 
 
        return $this; 
    } 
 
    public function getColor(): ?string 
    { 
        return $this->color; 
    } 
 
    public function setColor(string $color): self 
    { 
        $this->color = $color; 
 
        return $this; 
    } 
}