<?php
declare(strict_types=1);
namespace App\Domains\UserWord\Domain\Entity;
use App\Domains\User\Domain\Entity\User;
use App\Domains\UserWord\Domain\Enum\WordStatus;
use App\Domains\UserWord\Infrastructure\Repository\UserWordRepository;
use App\Domains\Word\Domain\Entity\Word;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UserWordRepository::class)]
#[ORM\Table(name: 'user_word')]
#[ORM\UniqueConstraint(name: 'unique_user_word', columns: ['user_id', 'word_id'])]
class UserWord
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false)]
private User $user;
#[ORM\ManyToOne(targetEntity: Word::class, cascade: ['persist'])]
#[ORM\JoinColumn(name: 'word_id', referencedColumnName: 'id', nullable: false)]
private Word $word;
#[ORM\Column(type: Types::STRING, enumType: WordStatus::class)]
private WordStatus $status;
#[ORM\Column(name: 'interval_days', type: Types::INTEGER)]
private int $intervalDays;
#[ORM\Column(name: 'ease_factor', type: Types::FLOAT)]
private float $easeFactor;
#[ORM\Column(type: Types::INTEGER)]
private int $repetition;
#[ORM\Column(name: 'next_review_date', type: Types::DATE_IMMUTABLE)]
private \DateTimeImmutable $nextReviewDate;
#[ORM\Column(name: 'created_at', type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $createdAt;
public function __construct(
User $user,
Word $word,
WordStatus $status = WordStatus::NEW,
int $intervalDays = 1,
float $easeFactor = 2.5,
int $repetition = 0,
DateTimeImmutable|null $nextReviewDate = null
) {
$this->user = $user;
$this->word = $word;
$this->status = $status;
$this->intervalDays = $intervalDays;
$this->easeFactor = $easeFactor;
$this->repetition = $repetition;
$this->nextReviewDate = $nextReviewDate ?? new DateTimeImmutable();
$this->createdAt = new DateTimeImmutable();
}
public function getId(): int|null
{
return $this->id;
}
public function getUser(): User
{
return $this->user;
}
public function getWord(): Word
{
return $this->word;
}
public function getStatus(): WordStatus
{
return $this->status;
}
public function getIntervalDays(): int
{
return $this->intervalDays;
}
public function getEaseFactor(): float
{
return $this->easeFactor;
}
public function getRepetition(): int
{
return $this->repetition;
}
public function getNextReviewDate(): DateTimeImmutable
{
return $this->nextReviewDate;
}
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
}