<?php

namespace App\Dto\Input;

use App\Entity\HardwareType;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;

class HardwareTypeInput
{
    #[Assert\NotBlank(message: 'validators.hardware_type.name.not_blank')]
    #[Groups(['hardware-type:write'])]
    public ?string $name = null;

    public function __construct(?HardwareType $hardwareType = null)
    {
        if (!$hardwareType) {
            return;
        }

        $this->name = $hardwareType->getName();
    }

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

        $hardwareType->setName($this->name);

        return $hardwareType;
    }

}