<?php

namespace App\Dto\Output;

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

#[Get(shortName: 'CommandTaskSchedule')]
class CommandTaskScheduleOutput extends AbstractOutput
{
    #[Groups(['command-task-schedule:read'])]
    #[ApiProperty(
        description: 'El tipo de recurrencia de la programación',
        example: 'weekly'
    )]
    public ?string $recurrenceType = null;

    #[Groups(['command-task-schedule:read'])]
    #[ApiProperty(
        description: 'La fecha de ejecución programada',
        example: '2024-01-20T00:00:00+00:00'
    )]
    public ?\DateTimeInterface $executionDate = null;

    #[Groups(['command-task-schedule:read'])]
    #[ApiProperty(
        description: 'La hora de ejecución programada',
        example: '2024-01-15T02:00:00+00:00'
    )]
    public ?\DateTimeInterface $executionTime = null;

    #[Groups(['command-task-schedule:read'])]
    #[ApiProperty(
        description: 'Los detalles de la recurrencia',
        example: ['days' => ['monday', 'wednesday', 'friday']]
    )]
    public ?array $recurrenceDetails = null;

    #[Groups(['command-task-schedule:read'])]
    #[ApiProperty(
        description: 'Indica si la programación está habilitada',
        example: true
    )]
    public ?bool $enabled = null;

    public function __construct(?CommandTaskSchedule $commandTaskSchedule = null)
    {
        parent::__construct($commandTaskSchedule);

        if (!$commandTaskSchedule) {
            return;
        }

        $this->recurrenceType = $commandTaskSchedule->getRecurrenceType();
        $this->executionTime = $commandTaskSchedule->getExecutionTime();
        $this->executionDate = $commandTaskSchedule->getExecutionDate();
        $this->recurrenceDetails = $commandTaskSchedule->getRecurrenceDetails();
        $this->enabled = $commandTaskSchedule->isEnabled();
    }
}