<?php

namespace App\Dto\Input;

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

final class SoftwareInput
{
    #[Assert\NotBlank]
    #[Groups(['software:write'])]
    #[ApiProperty(description: 'The name of the software', example: "Software 1")]
    public ?string $name = null;

    #[Groups(['software:write'])]
    #[ApiProperty(description: 'The description of the software', example: "Software 1 description")]
    public ?string $description = null;

    #[Groups(['software:write'])]
    #[ApiProperty(description: 'The type of the software', example: "Software 1 type")]
    public ?string $type = null;


    public function __construct(?Software $software = null)
    {
        if (!$software) {
            return;
        }

        $this->name = $software->getName();
        $this->description = $software->getDescription();
        $this->type = $software->getType();
    }

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

        $software->setName($this->name);
        $software->setDescription($this->description);
        $software->setType($this->type);

        return $software;
    }
}