<?php
declare(strict_types=1);
namespace App\Domains\UserPlan\Domain\Entity;
use App\Domains\Plan\Domain\Entity\Plan;
use App\Domains\User\Domain\Entity\User;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'user_subscription')]
class UserSubscription
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private int|null $id = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: false)]
private User $user;
#[ORM\ManyToOne(targetEntity: Plan::class)]
#[ORM\JoinColumn(nullable: false)]
private Plan $plan;
#[ORM\Column(type: 'datetime_immutable')]
private DateTimeImmutable $startDate;
#[ORM\Column(type: 'datetime_immutable')]
private DateTimeImmutable $endDate;
#[ORM\Column(type: 'boolean')]
private bool $isActive;
public function __construct(
User $user,
Plan $plan,
DateTimeImmutable $startDate,
DateTimeImmutable $endDate
) {
$this->user = $user;
$this->plan = $plan;
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->isActive = true;
}
// Getters
public function getId(): int|null
{
return $this->id;
}
public function getUser(): User
{
return $this->user;
}
public function getPlan(): Plan
{
return $this->plan;
}
public function getStartDate(): DateTimeImmutable
{
return $this->startDate;
}
public function getEndDate(): DateTimeImmutable
{
return $this->endDate;
}
public function isActive(): bool
{
return $this->isActive;
}
public function deactivate(): void
{
$this->isActive = false;
}
}