<?php
declare(strict_types=1);

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use App\Enum\CareerEnum;
use App\Enum\PlayerStatusEnum;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'player')]
#[ORM\UniqueConstraint(name: 'unique_user_game', columns: ['user_id', 'game_id'])]
#[ApiResource]
class Player
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'players')]
    #[ORM\JoinColumn(nullable: false)]
    private User $user;

    #[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'players')]
    #[ORM\JoinColumn(nullable: false)]
    private Game $game;

    #[ORM\Column(length: 100, nullable: false)]
    private string $name;

    #[ORM\Column(length: 24, enumType: CareerEnum::class, options: ['default' => CareerEnum::CORPORATION_EMPLOYEE])]
    private CareerEnum $career = CareerEnum::CORPORATION_EMPLOYEE;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
    private \DateTimeImmutable $joinedAt;

    #[ORM\Column(length: 24, enumType: PlayerStatusEnum::class, options: ['default' => PlayerStatusEnum::ACTIVE])]
    private PlayerStatusEnum $status = PlayerStatusEnum::ACTIVE;

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

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
    private ?\DateTimeImmutable $lastPlayedAt = null;

    public function __construct()
    {
        $this->joinedAt = new \DateTimeImmutable();
    }

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

    public function getUser(): User
    {
        return $this->user;
    }

    public function setUser(User $user): self
    {
        $this->user = $user;
        return $this;
    }

    public function getGame(): Game
    {
        return $this->game;
    }

    public function setGame(Game $game): self
    {
        $this->game = $game;
        return $this;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;
        return $this;
    }

    public function getCareer(): CareerEnum
    {
        return $this->career;
    }

    public function setCareer(CareerEnum $career): self
    {
        $this->career = $career;
        return $this;
    }

    public function getJoinedAt(): \DateTimeImmutable
    {
        return $this->joinedAt;
    }

    public function setJoinedAt(\DateTimeImmutable $joinedAt): self
    {
        $this->joinedAt = $joinedAt;
        return $this;
    }

    public function getStatus(): PlayerStatusEnum
    {
        return $this->status;
    }

    public function setStatus(PlayerStatusEnum $status): self
    {
        $this->status = $status;
        return $this;
    }

    public function getScore(): ?int
    {
        return $this->score;
    }

    public function setScore(?int $score): self
    {
        $this->score = $score;
        return $this;
    }

    public function getLastPlayedAt(): ?\DateTimeImmutable
    {
        return $this->lastPlayedAt;
    }

    public function setLastPlayedAt(?\DateTimeImmutable $lastPlayedAt): self
    {
        $this->lastPlayedAt = $lastPlayedAt;
        return $this;
    }
}