<?php

namespace App\Dto\Output;

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

#[Get(shortName: 'Hardware')]
final class HardwareOutput extends AbstractOutput
{
    #[Groups(['hardware:read', 'hardware-profile:read'])]
    #[ApiProperty(
        description: 'El nombre del componente de hardware',
        example: 'Intel Core i7-9700K'
    )]
    public string $name;

    #[Groups(['hardware:read'])]
    #[ApiProperty(
        description: 'La descripción del componente de hardware',
        example: 'Procesador de 8 núcleos a 3.6GHz'
    )]
    public ?string $description = '';

    #[Groups(['hardware:read'])]
    #[ApiProperty(
        description: 'El tipo de hardware',
        readableLink: true
    )]
    public ?HardwareTypeOutput $type = null;

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

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

    public function __construct(Hardware $hardware)
    {
        parent::__construct($hardware);

        $this->name = $hardware->getName();
        $this->description = $hardware->getDescription();
        $this->type = new HardwareTypeOutput($hardware->getType());
        $this->createdAt = $hardware->getCreatedAt();
        $this->createdBy = $hardware->getCreatedBy();
    }
}