<?php

namespace App\Dto\Output;

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

#[Get(shortName: 'Subnet')]
final class SubnetOutput extends AbstractOutput
{
    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'El nombre de la subred',
        example: 'Subred Principal'
    )]
    public string $name;

    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'La máscara de subred',
        example: '255.255.255.0'
    )]
    public string $netmask;

    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'La dirección IP de la subred',
        example: '192.168.1.0'
    )]
    public string $ipAddress;

    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'La dirección del servidor TFTP siguiente',
        example: '192.168.1.10'
    )]
    public ?string $nextServer = null;

    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'El nombre del archivo de arranque',
        example: 'pxelinux.0'
    )]
    public ?string $bootFileName = null;

    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'La dirección del router/gateway',
        example: '192.168.1.1'
    )]
    public ?string $router = null;

    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'La dirección del servidor DNS',
        example: '8.8.8.8'
    )]
    public ?string $dns = null;

    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'Indica si la subred está sincronizada',
        example: true
    )]
    public ?bool $synchronized = false;

    #[Groups(['subnet:read'])]
    #[ApiProperty(
        description: 'El ID del servidor DHCP',
        example: 1
    )]
    public ?int $serverId;

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

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

    public function __construct(Subnet $subnet)
    {
        parent::__construct($subnet);

        $this->name = $subnet->getName();
        $this->netmask = $subnet->getNetmask();
        $this->ipAddress = $subnet->getIpAddress();
        $this->nextServer = $subnet->getNextServer();
        $this->router = $subnet->getRouter();
        $this->dns = $subnet->getDns();
        $this->bootFileName = $subnet->getBootFileName();
        $this->synchronized = $subnet->isSynchronized();
        $this->serverId = $subnet->getServerId();
        $this->createdAt = $subnet->getCreatedAt();
        $this->createdBy = $subnet->getCreatedBy();
    }
}