<?php

namespace App\Dto\Input;

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'])]
    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;
    }

}