<?php

namespace App\Dto\Output;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;
use App\Entity\Menu;
use App\Entity\Trace;
use Symfony\Component\Serializer\Annotation\Groups;

#[Get(shortName: 'Trace')]
final class TraceOutput extends AbstractOutput
{
    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'El comando ejecutado',
        example: 'Reiniciar sistema'
    )]
    public ?string $command;

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'El cliente sobre el que se ejecutó el comando',
        example: null
    )]
    public ?ClientOutput $client = null;

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'El estado de la traza',
        example: 'completed'
    )]
    public string $status;

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'El ID del trabajo asociado',
        example: 'job-12345'
    )]
    public ?string $jobId = null;

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'Fecha de ejecución del comando',
        example: '2024-01-15T10:30:00+00:00'
    )]
    public ?\DateTimeInterface $executedAt = null;

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'La salida del comando ejecutado',
        example: 'Sistema reiniciado correctamente'
    )]
    public ?string $output = null;

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'Los parámetros de entrada del comando',
        example: []
    )]
    public ?array $input = null;

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'Fecha de finalización del comando',
        example: '2024-01-15T10:31:00+00:00'
    )]
    public ?\DateTimeInterface $finishedAt = null;

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'El progreso de ejecución (0.0 a 1.0)',
        example: 1.0
    )]
    public ?float $progress = null;

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

    #[Groups(['trace:read'])]
    #[ApiProperty(
        description: 'Usuario que creó este registro',
        example: 'admin'
    )]
    public ?string $createdBy = null;

    public function __construct(Trace $trace)
    {
        parent::__construct($trace);

        $this->command = $trace->getCommand();

        if ($trace->getClient() !== null) {
            $this->client = new ClientOutput($trace->getClient());
        }

        $this->status = $trace->getStatus();
        $this->jobId = $trace->getJobId();
        $this->executedAt = $trace->getExecutedAt();
        $this->output = $trace->getOutput();
        $this->input = $trace->getInput();
        $this->finishedAt = $trace->getFinishedAt();
        $this->progress = $trace->getProgress();
        $this->createdAt = $trace->getCreatedAt();
        $this->createdBy = $trace->getCreatedBy();
    }
}