<?php

namespace App\Dto\Output;

use ApiPlatform\Metadata\Get;
use App\Entity\Command;
use Symfony\Component\Serializer\Annotation\Groups;

#[Get(shortName: 'Command')]
final class CommandOutput extends AbstractOutput
{
    #[Groups(['command:read', 'command-group:read', 'command-task:read', 'trace:read'])]
    public string $name;

    #[Groups(['command:read', 'command-group:read', 'command-task:read', 'trace:read'])]
    public ?string $script = '';

    #[Groups(['command:read'])]
    public ?bool $readOnly = false;

    #[Groups(['command:read'])]
    public ?bool $enabled = true;

    #[Groups(['command:read'])]
    public ?bool $parameters = true;

    #[Groups(['command:read'])]
    public ?string $comments = '';

    #[Groups(['command:read'])]
    public \DateTime $createdAt;

    #[Groups(['command:read'])]
    public ?string $createdBy = null;

    public function __construct(Command $command)
    {
        parent::__construct($command);

        $this->name = $command->getName();
        $this->script = $command->getScript();
        $this->readOnly = $command->isReadOnly();
        $this->parameters = $command->isParameters();
        $this->enabled = $command->isEnabled();
        $this->comments = $command->getComments();
        $this->createdAt = $command->getCreatedAt();
        $this->createdBy = $command->getCreatedBy();
    }
}