<?php

namespace App\Dto\Input;

use ApiPlatform\Metadata\ApiProperty;
use App\Entity\OperativeSystem;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;

class OperativeSystemInput
{
    #[Assert\NotBlank(message: 'validators.operative_system.name.not_blank')]
    #[Groups(['operative-system:write'])]
    #[ApiProperty(
        description: 'El nombre del sistema operativo',
        example: 'Ubuntu 20.04 LTS'
    )]
    public ?string $name = null;

    public function __construct(?OperativeSystem $operativeSystem = null)
    {
        if (!$operativeSystem) {
            return;
        }

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

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

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

        return $operativeSystem;
    }

}