<?php

namespace App\Dto\Input;

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

final class MenuInput
{
    #[Assert\NotNull()]
    #[Groups(['menu:write'])]
    #[ApiProperty(description: 'The name of the menu', example: "Menu 1")]
    public ?string $name = null;

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

    #[Assert\NotNull()]
    #[Groups(['menu:write'])]
    #[ApiProperty(description: 'The resolution of the menu', example: "1920x1080")]
    public ?string $resolution = null;

    #[Groups(['menu:write'])]
    #[ApiProperty(description: 'The public url of the menu', example: "http://example.com")]
    public ?string $publicUrl = null;

    #[Groups(['menu:write'])]
    #[ApiProperty(description: 'The private url of the menu', example: "http://example.com")]
    public ?string $privateUrl = null;

    #[Groups(['menu:write'])]
    #[ApiProperty(description: 'The default menu', example: "false")]
    public ?bool $isDefault = false;

    public function __construct(?Menu $menu = null)
    {
        if (!$menu) {
            return;
        }

        $this->name = $menu->getName();
        $this->comments = $menu->getComments();
        $this->resolution = $menu->getResolution();
        $this->publicUrl = $menu->getPublicUrl();
        $this->privateUrl = $menu->getPrivateUrl();
        $this->isDefault = $menu->isDefault();
    }

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

        $menu->setName($this->name);
        $menu->setComments($this->comments);
        $menu->setResolution($this->resolution);
        $menu->setPublicUrl($this->publicUrl);
        $menu->setPrivateUrl($this->privateUrl);
        $menu->setIsDefault($this->isDefault);

        return $menu;
    }
}