<?php

declare(strict_types=1);

namespace App\Administration\Application\Query\GetParentInvitations;

use App\Administration\Domain\Model\Invitation\ParentInvitation;
use DateTimeImmutable;

final readonly class ParentInvitationDto
{
    public function __construct(
        public string $id,
        public string $studentId,
        public string $parentEmail,
        public string $status,
        public DateTimeImmutable $createdAt,
        public DateTimeImmutable $expiresAt,
        public ?DateTimeImmutable $sentAt,
        public ?DateTimeImmutable $activatedAt,
        public ?string $activatedUserId,
        public ?string $studentFirstName = null,
        public ?string $studentLastName = null,
    ) {
    }

    public static function fromDomain(ParentInvitation $invitation, ?string $studentFirstName = null, ?string $studentLastName = null): self
    {
        return new self(
            id: (string) $invitation->id,
            studentId: (string) $invitation->studentId,
            parentEmail: (string) $invitation->parentEmail,
            status: $invitation->status->value,
            createdAt: $invitation->createdAt,
            expiresAt: $invitation->expiresAt,
            sentAt: $invitation->sentAt,
            activatedAt: $invitation->activatedAt,
            activatedUserId: $invitation->activatedUserId !== null ? (string) $invitation->activatedUserId : null,
            studentFirstName: $studentFirstName,
            studentLastName: $studentLastName,
        );
    }
}
