<?php

namespace App\Dto\Output;

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

#[Get(shortName: 'RemoteCalendar')]
final class RemoteCalendarOutput extends AbstractOutput
{
    #[Groups(['remote-calendar:read', 'organizational-unit:read'])]
    #[ApiProperty(
        description: 'El nombre del calendario remoto',
        example: 'Horario Escolar'
    )]
    public ?string $name = null;

    /**
     * @var RemoteCalendarRuleOutput[]
     */
    #[Groups(['remote-calendar:read'])]
    #[ApiProperty(
        description: 'Las reglas del calendario remoto',
        example: []
    )]
    public array $remoteCalendarRules = [];

    #[Groups(['remote-calendar:read'])]
    #[ApiProperty(
        description: 'Fecha de creación del calendario',
        example: '2024-01-15T10:30:00+00:00'
    )]
    public ?\DateTimeInterface $createdAt = null;

    public function __construct(RemoteCalendar $remoteCalendar)
    {
        parent::__construct($remoteCalendar);

        $this->name = $remoteCalendar->getName();

        $this->remoteCalendarRules = $remoteCalendar->getRules()->map(
            fn(RemoteCalendarRule $rule) => new RemoteCalendarRuleOutput($rule)
        )->toArray();

        $this->createdAt = $remoteCalendar->getCreatedAt();
    }
}