<?php

namespace App\Dto\Output;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;
use App\Entity\Hardware;
use App\Entity\HardwareProfile;
use Symfony\Component\Serializer\Annotation\Groups;

#[Get(shortName: 'HardwareProfile')]
final class HardwareProfileOutput extends AbstractOutput
{
    #[Groups(['hardware-profile:read', 'client:read'])]
    #[ApiProperty(
        description: 'La descripción del perfil de hardware',
        example: 'Perfil de hardware estándar para aula de informática'
    )]
    public ?string $description = '';

    #[Groups(['hardware-profile:read'])]
    #[ApiProperty(
        description: 'Comentarios adicionales sobre el perfil',
        example: 'Configuración actualizada en enero 2024'
    )]
    public ?string $comments = '';

    #[Groups(['hardware-profile:read'])]
    #[ApiProperty(
        description: 'El cliente asociado a este perfil de hardware',
        example: null
    )]
    public ?ClientOutput $client = null;

    #[Groups(['hardware-profile:read'])]
    #[ApiProperty(
        description: 'La colección de componentes de hardware',
        example: []
    )]
    public ?array $hardwareCollection = [];

    #[Groups(['hardware-profile:read'])]
    #[ApiProperty(
        description: 'Fecha de creación del perfil de hardware',
        example: '2024-01-15T10:30:00+00:00'
    )]
    public \DateTime $createdAt;

    #[Groups(['hardware-profile:read'])]
    #[ApiProperty(
        description: 'Usuario que creó este registro',
        example: 'admin'
    )]
    public ?string $createdBy = null;

    public function __construct(HardwareProfile $hardwareProfile)
    {
        parent::__construct($hardwareProfile);

        $this->description = $hardwareProfile->getDescription();
        $this->comments = $hardwareProfile->getComments();
        if($hardwareProfile->getClient()) {
            $this->client = new ClientOutput($hardwareProfile->getClient());
        }

        $this->hardwareCollection = $hardwareProfile->getHardwareCollection()->map(
            fn(Hardware $hardware) => new HardwareOutput($hardware)
        )->toArray();

        $this->createdAt = $hardwareProfile->getCreatedAt();
        $this->createdBy = $hardwareProfile->getCreatedBy();
    }
}