<?php
namespace App\Entity;
use App\Repository\RapperRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use phpDocumentor\Reflection\Types\This;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: RapperRepository::class)]
#[Vich\Uploadable]
class Rapper
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $pseudoname = null;
#[ORM\OneToOne(inversedBy: 'rapper', cascade: ['persist', 'remove'])]
private ?Client $client = null;
#[ORM\OneToMany(mappedBy: 'challenger', targetEntity: Battle::class)]
private Collection $battles_challenger;
#[ORM\OneToMany(mappedBy: 'oponnent', targetEntity: Battle::class)]
private Collection $battles_oponnent;
#[Vich\UploadableField(mapping: 'rappers_image', fileNameProperty: 'avatarName', size: 'avatarSize')]
public ?File $avatarFile = null;
#[ORM\Column(nullable: true)]
private ?string $avatarName = null;
#[ORM\Column(nullable: true)]
private ?int $avatarSize = null;
#[ORM\Column(nullable: true)]
private ?\DateTime $updatedAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTime $createdAt = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $rapperStyle = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $bio = null;
#[ORM\OneToMany(mappedBy: 'rapper', targetEntity: SocialLink::class)]
private Collection $socialLinks;
#[ORM\ManyToOne(inversedBy: 'rappers')]
private ?Crew $crew = null;
#[ORM\OneToMany(mappedBy: 'winner', targetEntity: Battle::class)]
private Collection $wonBattles;
#[ORM\Column]
private ?int $rank = null;
#[ORM\ManyToMany(targetEntity: Client::class, inversedBy: 'rappersFollowed')]
private Collection $followers;
public function __toArray(): array
{
return [
"id"=>$this->getId(),
"pseudoname"=>$this->getPseudoname(),
"crew"=>$this->getCrew(),
"rank"=>$this->getRank(),
"avatarName"=>$this->getAvatarName(),
"avatarSize"=>$this->getAvatarSize(),
"createdAt"=>$this->getCreatedAt(),
"updatedAt"=>$this->getUpdatedAt(),
"followers"=>$this->getFollowers(),
];
}
public function __toString()
{
return (string)$this->getPseudoname();
}
public function __construct()
{
$this->battles_challenger = new ArrayCollection();
$this->battles_oponnent = new ArrayCollection();
$this->socialLinks = new ArrayCollection();
$this->wonBattles = new ArrayCollection();
$this->followers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): static
{
$this->client = $client;
return $this;
}
/**
* @return Collection<int, Battle>
*/
public function getBattlesChallenger(): Collection
{
return $this->battles_challenger;
}
public function addBattlesChallenger(Battle $battlesChallenger): static
{
if (!$this->battles_challenger->contains($battlesChallenger)) {
$this->battles_challenger->add($battlesChallenger);
$battlesChallenger->setChallenger($this);
}
return $this;
}
public function removeBattlesChallenger(Battle $battlesChallenger): static
{
if ($this->battles_challenger->removeElement($battlesChallenger)) {
// set the owning side to null (unless already changed)
if ($battlesChallenger->getChallenger() === $this) {
$battlesChallenger->setChallenger(null);
}
}
return $this;
}
/**
* @return Collection<int, Battle>
*/
public function getBattlesOponnent(): Collection
{
return $this->battles_oponnent;
}
public function addBattlesOponnent(Battle $battlesOponnent): static
{
if (!$this->battles_oponnent->contains($battlesOponnent)) {
$this->battles_oponnent->add($battlesOponnent);
$battlesOponnent->setOponnent($this);
}
return $this;
}
public function removeBattlesOponnent(Battle $battlesOponnent): static
{
if ($this->battles_oponnent->removeElement($battlesOponnent)) {
// set the owning side to null (unless already changed)
if ($battlesOponnent->getOponnent() === $this) {
$battlesOponnent->setOponnent(null);
}
}
return $this;
}
public function getPseudoname(): ?string
{
return $this->pseudoname;
}
public function setPseudoname(?string $pseudoname): static
{
$this->pseudoname = $pseudoname;
return $this;
}
public function setAvatarFile(?File $avatarFile = null): void
{
$this->avatarFile = $avatarFile;
if ($this->avatarFile instanceof UploadedFile) {
$this->updatedAt = new \DateTime('now');
}
}
public function getAvatarFile(): ?File
{
return $this->avatarFile;
}
public function setAvatarName(?string $imageName): void
{
$this->avatarName = $imageName;
}
public function getAvatarName(): ?string
{
return $this->avatarName;
}
public function setAvatarSize(?int $imageSize): void
{
$this->avatarSize = $imageSize;
}
public function getAvatarSize(): ?int
{
return $this->avatarSize;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTime $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getRapperStyle(): ?string
{
return $this->rapperStyle;
}
public function setRapperStyle(?string $rapperStyle): static
{
$this->rapperStyle = $rapperStyle;
return $this;
}
public function getBio(): ?string
{
return $this->bio;
}
public function setBio(?string $bio): static
{
$this->bio = $bio;
return $this;
}
/**
* @return Collection<int, SocialLink>
*/
public function getSocialLinks(): Collection
{
return $this->socialLinks;
}
public function addSocialLink(SocialLink $socialLink): static
{
if (!$this->socialLinks->contains($socialLink)) {
$this->socialLinks->add($socialLink);
$socialLink->setRapper($this);
}
return $this;
}
public function removeSocialLink(SocialLink $socialLink): static
{
if ($this->socialLinks->removeElement($socialLink)) {
// set the owning side to null (unless already changed)
if ($socialLink->getRapper() === $this) {
$socialLink->setRapper(null);
}
}
return $this;
}
public function getCrew(): ?Crew
{
return $this->crew;
}
public function setCrew(?Crew $crew): static
{
$this->crew = $crew;
return $this;
}
/**
* @return Collection<int, Battle>
*/
public function getWonBattles(): Collection
{
return $this->wonBattles;
}
public function addWonBattle(Battle $wonBattle): static
{
if (!$this->wonBattles->contains($wonBattle)) {
$this->wonBattles->add($wonBattle);
$wonBattle->setWinner($this);
}
return $this;
}
public function removeWonBattle(Battle $wonBattle): static
{
if ($this->wonBattles->removeElement($wonBattle)) {
// set the owning side to null (unless already changed)
if ($wonBattle->getWinner() === $this) {
$wonBattle->setWinner(null);
}
}
return $this;
}
public function getRank(): ?int
{
return $this->rank;
}
public function setRank(?int $rank): static
{
$this->rank = $rank;
return $this;
}
/**
* @return Collection<int, Client>
*/
public function getFollowers(): Collection
{
return $this->followers;
}
public function addFollower(Client $follower): static
{
if (!$this->followers->contains($follower)) {
$this->followers->add($follower);
}
return $this;
}
public function removeFollower(Client $follower): static
{
$this->followers->removeElement($follower);
return $this;
}
}