<?php
namespace App\Entity;
use App\Repository\UserTeamRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UserTeamRepository::class)]
class UserTeam
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'userTeams')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;
#[ORM\ManyToOne(inversedBy: 'userTeams')]
#[ORM\JoinColumn(nullable: false)]
private ?Team $team = null;
#[ORM\Column(length: 50)]
private ?string $role = null;
#[ORM\Column]
private ?\DateTimeImmutable $joinedAt = null;
/**
* Available team roles
*/
public const ROLE_MEMBER = 'member';
public const ROLE_CAPTAIN = 'captain';
/**
* Get all available team roles
*
* @return array<string, string>
*/
public static function getAvailableRoles(): array
{
return [
'Team Member' => self::ROLE_MEMBER,
'Team Captain' => self::ROLE_CAPTAIN,
];
}
public function __construct()
{
$this->joinedAt = new \DateTimeImmutable();
$this->role = self::ROLE_MEMBER;
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
return $this;
}
public function getTeam(): ?Team
{
return $this->team;
}
public function setTeam(?Team $team): static
{
$this->team = $team;
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(string $role): static
{
$this->role = $role;
return $this;
}
public function getJoinedAt(): ?\DateTimeImmutable
{
return $this->joinedAt;
}
public function setJoinedAt(\DateTimeImmutable $joinedAt): static
{
$this->joinedAt = $joinedAt;
return $this;
}
/**
* Check if user is a team captain
*/
public function isTeamLeader(): bool
{
return $this->role === self::ROLE_CAPTAIN;
}
/**
* Check if user has a specific team role
*/
public function hasRole(string $role): bool
{
return $this->role === $role;
}
/**
* Check if user can manage team members
*/
public function canManageMembers(): bool
{
return $this->role === self::ROLE_CAPTAIN;
}
/**
* Check if user can manage team settings
*/
public function canManageTeam(): bool
{
return $this->role === self::ROLE_CAPTAIN;
}
}