<?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', 'organizational-unit:read'])]
    public ?string $description = '';

    #[Groups(['hardware-profile:read'])]
    public ?string $comments = '';

    #[Groups(['hardware-profile:read'])]
    public ?OrganizationalUnitOutput $organizationalUnit = null;

    #[Groups(['hardware-profile:read'])]
    public ?array $hardwareCollection = [];

    #[Groups(['hardware-profile:read'])]
    public \DateTime $createdAt;

    #[Groups(['hardware-profile:read'])]
    public ?string $createdBy = null;

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

        $this->description = $hardwareProfile->getDescription();
        $this->comments = $hardwareProfile->getComments();
        if($hardwareProfile->getOrganizationalUnit()) {
            $this->organizationalUnit = new OrganizationalUnitOutput($hardwareProfile->getOrganizationalUnit());
        }

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

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