<?php

namespace App\Dto\Output;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;
use App\Entity\CommandTaskSchedule;
use App\Entity\CommandTaskScript;
use Symfony\Component\Serializer\Annotation\Groups;

#[Get(shortName: 'CommandTaskScript')]
class CommandTaskScriptOutput extends AbstractOutput
{
    #[Groups(['command-task-script:read'])]
    #[ApiProperty(
        description: 'El contenido del script',
        example: '#!/bin/bash\necho "Hello World"'
    )]
    public ?string $content = null;

    #[Groups(['command-task-script:read'])]
    #[ApiProperty(
        description: 'El tipo de script',
        example: 'bash'
    )]
    public ?string $type = null;

    #[Groups(['command-task-script:read'])]
    #[ApiProperty(
        description: 'Los parámetros del script',
        example: []
    )]
    public ?array $parameters = null;

    #[Groups(['command-task-script:read'])]
    #[ApiProperty(
        description: 'La tarea de comando asociada',
        example: null
    )]
    public ?CommandTaskOutput $commandTaskOutput = null;

    #[Groups(['command-task-script:read'])]
    #[ApiProperty(
        description: 'El orden de ejecución del script',
        example: 1
    )]
    public ?int $order = null;

    public function __construct(?CommandTaskScript $commandTaskScript = null)
    {
        parent::__construct($commandTaskScript);

        if (!$commandTaskScript) {
            return;
        }

        $this->content = $commandTaskScript->getContent();
        $this->order = $commandTaskScript->getExecutionOrder();
        $this->type = $commandTaskScript->getType();
        $this->parameters = $commandTaskScript->getParameters();
        $this->commandTaskOutput = new CommandTaskOutput($commandTaskScript->getCommandTask());
    }
}