<?php

declare(strict_types=1);

namespace App\Administration\Application\Query\GetParentsForStudent;

use App\Administration\Domain\Model\StudentGuardian\StudentGuardian;
use App\Administration\Domain\Model\User\User;
use DateTimeImmutable;

/**
 * DTO représentant un parent/tuteur lié à un élève.
 */
final readonly class GuardianForStudentDto
{
    public function __construct(
        public string $linkId,
        public string $guardianId,
        public string $relationshipType,
        public string $relationshipLabel,
        public DateTimeImmutable $linkedAt,
        public string $firstName,
        public string $lastName,
        public string $email,
    ) {
    }

    public static function fromDomainWithUser(StudentGuardian $link, User $guardian): self
    {
        return new self(
            linkId: (string) $link->id,
            guardianId: (string) $link->guardianId,
            relationshipType: $link->relationshipType->value,
            relationshipLabel: $link->relationshipType->label(),
            linkedAt: $link->createdAt,
            firstName: $guardian->firstName,
            lastName: $guardian->lastName,
            email: (string) $guardian->email,
        );
    }
}
