<?php

namespace App\Dto\Output;

use ApiPlatform\Metadata\ApiProperty;
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'])]
    #[ApiProperty(
        description: 'El nombre del comando',
        example: 'Reiniciar sistema'
    )]
    public string $name;

    #[Groups(['command:read', 'command-group:read', 'command-task:read', 'trace:read'])]
    #[ApiProperty(
        description: 'El script del comando',
        example: 'reboot'
    )]
    public ?string $script = '';

    #[Groups(['command:read'])]
    #[ApiProperty(
        description: 'Indica si el comando es de solo lectura',
        example: false
    )]
    public ?bool $readOnly = false;

    #[Groups(['command:read'])]
    #[ApiProperty(
        description: 'Indica si el comando está habilitado',
        example: true
    )]
    public ?bool $enabled = true;

    #[Groups(['command:read'])]
    #[ApiProperty(
        description: 'Indica si el comando acepta parámetros',
        example: true
    )]
    public ?bool $parameters = true;

    #[Groups(['command:read'])]
    #[ApiProperty(
        description: 'Comentarios sobre el comando',
        example: 'Reinicia el equipo de forma controlada'
    )]
    public ?string $comments = '';

    #[Groups(['command:read'])]
    #[ApiProperty(
        description: 'Fecha de creación del comando',
        example: '2024-01-15T10:30:00+00:00'
    )]
    public \DateTime $createdAt;

    #[Groups(['command:read'])]
    #[ApiProperty(
        description: 'Usuario que creó este registro',
        example: 'admin'
    )]
    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();
    }
}