<?php

namespace App\Dto\Input;

use ApiPlatform\Metadata\ApiProperty;
use App\Entity\HardwareProfile;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Dto\Output\ClientOutput;

final class HardwareProfileInput
{
    #[Groups(['hardware-profile:write'])]
    #[ApiProperty(description: 'The description of the hardware profile', example: "Hardware 1 description")]
    public ?string $description = null;

    #[Groups(['hardware-profile:write'])]
    #[ApiProperty(description: 'Comments of the hardware profile', example: "Hardware 1")]
    public ?string $comments = null;

    #[Groups(['hardware-profile:write'])]
    #[ApiProperty(description: 'The client of the hardware profile', readableLink: true)]
    public ?ClientOutput $client = null;

    public function __construct(?HardwareProfile $hardwareProfile = null)
    {
        if (!$hardwareProfile) {
            return;
        }

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

    public function createOrUpdateEntity(?HardwareProfile $hardwareProfile = null): HardwareProfile
    {
        if (!$hardwareProfile) {
            $hardwareProfile = new HardwareProfile();
        }

        $hardwareProfile->setDescription($this->description);
        $hardwareProfile->setComments($this->comments);
        $hardwareProfile->setClient($this->client->getEntity());

        return $hardwareProfile;
    }
}