<?php

namespace App\Entity;

use App\Repository\PartyRequestRepository;
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\UuidType;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: PartyRequestRepository::class)]
class PartyRequest
{
   #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, nullable: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
    private ?Uuid $id = null;

    #[ORM\ManyToOne(inversedBy: 'partyRequests')]
    #[ORM\JoinColumn(nullable: false)]
    private ?User $requester = null;

    #[ORM\Column]
    private ?\DateTime $dateRequest = null;

    #[ORM\ManyToOne]
    private ?User $moderator = null;

    #[ORM\Column(nullable: true)]
    private ?\DateTime $modOnDate = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false)]
    private ?Game $gameChoosen = null;

    #[ORM\ManyToOne]
    private ?Gamemaster $gamemasterChoosen = null;

    #[ORM\ManyToOne(inversedBy: 'partyRequests')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Event $event = null;

    #[ORM\Column(nullable: true)]
    private ?bool $accepted = null;

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

    public function getState(): ?array
    {
        $state = ['code' => 'REFUSED', 'name' => 'Refusée'];
        if (is_null($this->modOnDate) && is_null($this->accepted)) {
            $state = ['code' => 'WAIT', 'name' => 'En attente'];
        }
        if ($this->accepted) {
            $state =  ['code' => 'ACCEPTED', 'name' => 'Acceptée'];;
        }
        return $state;
    }

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

    public function getRequester(): ?User
    {
        return $this->requester;
    }

    public function setRequester(?User $requester): static
    {
        $this->requester = $requester;

        return $this;
    }

    public function getDateRequest(): ?\DateTime
    {
        return $this->dateRequest;
    }

    public function setDateRequest(\DateTime $dateRequest): static
    {
        $this->dateRequest = $dateRequest;

        return $this;
    }

    public function getModerator(): ?User
    {
        return $this->moderator;
    }

    public function setModerator(?User $moderator): static
    {
        $this->moderator = $moderator;

        return $this;
    }

    public function getModOnDate(): ?\DateTime
    {
        return $this->modOnDate;
    }

    public function setModOnDate(?\DateTime $modOnDate): static
    {
        $this->modOnDate = $modOnDate;

        return $this;
    }

    public function getGameChoosen(): ?Game
    {
        return $this->gameChoosen;
    }

    public function setGameChoosen(?Game $gameChoosen): static
    {
        $this->gameChoosen = $gameChoosen;

        return $this;
    }

    public function getGamemasterChoosen(): ?Gamemaster
    {
        return $this->gamemasterChoosen;
    }

    public function setGamemasterChoosen(?Gamemaster $gamemasterChoosen): static
    {
        $this->gamemasterChoosen = $gamemasterChoosen;

        return $this;
    }

    public function getEvent(): ?Event
    {
        return $this->event;
    }

    public function setEvent(?Event $event): static
    {
        $this->event = $event;

        return $this;
    }

    public function isAccepted(): ?bool
    {
        return $this->accepted;
    }

    public function setAccepted(?bool $accepted): static
    {
        $this->accepted = $accepted;

        return $this;
    }

    public function getMessage(): ?string
    {
        return $this->message;
    }

    public function setMessage(?string $message): static
    {
        $this->message = $message;

        return $this;
    }
}
