<?php

declare(strict_types=1);

namespace App\Administration\Infrastructure\Api\Resource;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use App\Administration\Application\Query\GetStudentsForParent\StudentForParentDto;
use App\Administration\Infrastructure\Api\Provider\MyChildrenProvider;

/**
 * API Resource pour les enfants du parent connecté.
 *
 * @see Story 2.7 - Liaison Parents-Enfants (AC2)
 */
#[ApiResource(
    shortName: 'MyChildren',
    operations: [
        new GetCollection(
            uriTemplate: '/me/children',
            provider: MyChildrenProvider::class,
            name: 'get_my_children',
        ),
    ],
)]
final class MyChildrenResource
{
    #[ApiProperty(identifier: true)]
    public ?string $id = null;

    public ?string $studentId = null;

    public ?string $relationshipType = null;

    public ?string $relationshipLabel = null;

    public ?string $firstName = null;

    public ?string $lastName = null;

    public static function fromDto(StudentForParentDto $dto): self
    {
        $resource = new self();
        $resource->id = $dto->linkId;
        $resource->studentId = $dto->studentId;
        $resource->relationshipType = $dto->relationshipType;
        $resource->relationshipLabel = $dto->relationshipLabel;
        $resource->firstName = $dto->firstName;
        $resource->lastName = $dto->lastName;

        return $resource;
    }
}
