<?php

namespace App\Dto\Input;

use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\ClientOutput;
use App\Dto\Output\ImageOutput;
use App\Dto\Output\OperativeSystemOutput;
use App\Dto\Output\OrganizationalUnitOutput;
use App\Entity\HardwareProfile;
use App\Entity\ImageRepository;
use App\Entity\Menu;
use App\Entity\Partition;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;

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

    #[Assert\NotBlank]
    #[Groups(['repository:write'])]
    #[ApiProperty(description: 'The IP of the repository', example: "")]
    public ?string $ip = null;

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

    #[Assert\NotBlank]
    #[Groups(['repository:write'])]
    #[ApiProperty(description: 'The user of the repository', example: "Repository user")]
    public ?string $user = 'opengnsys';

    #[Groups(['repository:write'])]
    #[ApiProperty(description: 'The sshPort of the repository', example: "Repository ssh port")]
    public ?string $sshPort = '22';


    public function __construct(?ImageRepository $repository = null)
    {
        if (!$repository) {
            return;
        }

        $this->name = $repository->getName();
        $this->ip = $repository->getIp();
        $this->comments = $repository->getComments();
        $this->user = $repository->getUser();
        $this->sshPort = $repository->getSshPort();
    }

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

        $repository->setName($this->name);
        $repository->setIp($this->ip);
        $repository->setComments($this->comments);
        $repository->setUser($this->user);
        $repository->setSshPort($this->sshPort);

        return $repository;
    }
}