<?php

namespace App\Dto\Output;

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

#[Get(shortName: 'PxeTemplate')]
final class PxeTemplateOutput extends AbstractOutput
{
    #[Groups(['pxe-template:read', 'client:read', 'organizational-unit:read'])]
    #[ApiProperty(
        description: 'El nombre de la plantilla PXE',
        example: 'Plantilla BIOS'
    )]
    public string $name;

    #[Groups(['pxe-template:read'])]
    #[ApiProperty(
        description: 'Indica si la plantilla está sincronizada',
        example: true
    )]
    public ?bool $synchronized = null;

    #[Groups(['pxe-template:read'])]
    #[ApiProperty(
        description: 'El contenido de la plantilla PXE',
        example: 'DEFAULT ogLive\nPROMPT 0\nTIMEOUT 0...'
    )]
    public ?string $templateContent = '';

    #[Groups(['pxe-template:read'])]
    #[ApiProperty(
        description: 'Indica si es la plantilla predeterminada',
        example: true
    )]
    public ?bool $isDefault = null;

    #[Groups(['pxe-template:read'])]
    #[ApiProperty(
        description: 'El número de clientes que usan esta plantilla',
        example: 15
    )]
    public ?int $clientsLength = 0;

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

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

    public function __construct(PxeTemplate $pxeTemplate)
    {
        parent::__construct($pxeTemplate);

        $this->name = $pxeTemplate->getName();
        $this->synchronized = $pxeTemplate->isSynchronized();
        $this->templateContent = $pxeTemplate->getTemplateContent();
        $this->clientsLength = $pxeTemplate->getClients()->count();
        $this->isDefault = $pxeTemplate->isDefault();
        $this->createdAt = $pxeTemplate->getCreatedAt();
        $this->createdBy = $pxeTemplate->getCreatedBy();
    }
}