<?php
declare(strict_types=1);
namespace App\Entity\Core\Gamification;
use App\Entity\Core\KvikCustomization;
use App\Entity\Core\KvikCustomizationBuy;
use App\Entity\User\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
#[ORM\Table('gamification_profile')]
#[ORM\Entity(repositoryClass: GamificationProfileRepository::class)]
class GamificationProfile implements JsonSerializable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private int $id;
#[ORM\JoinColumn(name: 'student', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\ManyToOne(targetEntity: User::class)]
private User $student;
#[ORM\Column(name: 'current_points', type: 'integer', options: ['default' => 0])]
private int $currentPoints = 0;
#[ORM\Column(name: 'spent_points', type: 'integer', options: ['default' => 0])]
private int $spentPoints = 0;
#[ORM\OneToMany(targetEntity: KvikCustomizationBuy::class, mappedBy: 'gamificationProfile', cascade: ['persist'])]
private Collection $kvikCustomizationBuys;
#[ORM\JoinTable(name: 'kvik_customization_selection')]
#[ORM\JoinColumn(name: 'gamification_profile', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'kvik_customization', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: KvikCustomization::class)]
private Collection $selectedKvikCustomizations;
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private bool $themeEnabled = true;
public function __construct()
{
$this->selectedKvikCustomizations = new ArrayCollection();
$this->kvikCustomizationBuys = new ArrayCollection();
}
public function hasThemeEnabled(): bool
{
return $this->themeEnabled;
}
public function setThemeEnabled(bool $themeEnabled): void
{
$this->themeEnabled = $themeEnabled;
}
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getStudent(): User
{
return $this->student;
}
public function setStudent(User $student): void
{
$this->student = $student;
}
public function getCurrentPoints(): int
{
return $this->currentPoints;
}
public function setCurrentPoints(int $currentPoints): void
{
$this->currentPoints = $currentPoints;
}
public function getSpentPoints(): int
{
return $this->spentPoints;
}
public function setSpentPoints(int $spentPoints): void
{
$this->spentPoints = $spentPoints;
}
public function getKvikCustomizationBuys(): Collection
{
return $this->kvikCustomizationBuys;
}
public function setKvikCustomizationBuys(Collection $kvikCustomizationBuys): void
{
$this->kvikCustomizationBuys = $kvikCustomizationBuys;
}
public function getSelectedKvikCustomizations(): Collection
{
return $this->selectedKvikCustomizations;
}
public function setSelectedKvikCustomizations(Collection $selectedKvikCustomizations): void
{
$this->selectedKvikCustomizations = $selectedKvikCustomizations;
}
public function spendPoints(int $points): void
{
if ($points > $this->currentPoints)
return;
$this->currentPoints -= $points;
$this->spentPoints += $points;
}
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'student' => $this->student,
'currentPoints' => $this->currentPoints,
'spentPoints' => $this->spentPoints,
'selectedKvikCustomizations' => $this->selectedKvikCustomizations->toArray(),
'themeEnabled' => $this->themeEnabled
];
}
}