<?php

namespace App\Dto\Output;

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

#[Get(shortName: 'OgLive')]
final class OgLiveOutput extends AbstractOutput
{
    #[Groups(['og-live:read', 'client:read', "organizational-unit:read"])]
    #[ApiProperty(
        description: 'El nombre de la imagen OGLive',
        example: 'ogLive-5.2.0'
    )]
    public ?string $name = '';

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

    #[Groups(['og-live:read'])]
    #[ApiProperty(
        description: 'Indica si la imagen está instalada',
        example: true
    )]
    public ?bool $installed = false;

    #[Groups(['og-live:read'])]
    #[ApiProperty(
        description: 'Indica si es la imagen OGLive predeterminada',
        example: true
    )]
    public ?bool $isDefault = false;

    #[Groups(['og-live:read'])]
    #[ApiProperty(
        description: 'URL de descarga de la imagen',
        example: 'https://opengnsys.es/svn/branches/version1.1/installer/ogLive-5.2.0-r6374.iso'
    )]
    public ?string $downloadUrl = '';

    #[Groups(['og-live:read'])]
    #[ApiProperty(
        description: 'El estado de la imagen',
        example: 'synchronized'
    )]
    public ?string $status = '';

    #[Groups(['og-live:read'])]
    #[ApiProperty(
        description: 'Suma de verificación de la imagen',
        example: 'a1b2c3d4e5f6...'
    )]
    public ?string $checksum = '';

    #[Groups(['og-live:read'])]
    #[ApiProperty(
        description: 'La distribución de Linux',
        example: 'Ubuntu'
    )]
    public ?string $distribution = '';

    #[Groups(['og-live:read'])]
    #[ApiProperty(
        description: 'La revisión de la imagen',
        example: 'r6374'
    )]
    public ?string $revision = '';

    #[Groups(['og-live:read', 'client:read', "organizational-unit:read"])]
    #[ApiProperty(
        description: 'El nombre del archivo de la imagen',
        example: 'ogLive-5.2.0-r6374.iso'
    )]
    public ?string $filename = null;

    #[Groups(['og-live:read', 'client:read', "organizational-unit:read"])]
    #[ApiProperty(
        description: 'La versión del kernel',
        example: '5.4.0-42-generic'
    )]
    public ?string $kernel = '';

    #[Groups(['og-live:read'])]
    #[ApiProperty(
        description: 'La arquitectura del sistema',
        example: 'amd64'
    )]
    public ?string $architecture = '';

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

    #[Groups(['og-live:read', 'client:read', "organizational-unit:read"])]
    #[ApiProperty(
        description: 'Fecha de la imagen',
        example: '2024-01-10T00:00:00+00:00'
    )]
    public ?\DateTimeInterface $date;

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

    public function __construct(OgLive $ogLive)
    {
        parent::__construct($ogLive);

        $this->name = $ogLive->getName();
        $this->synchronized = $ogLive->isSynchronized();
        $this->installed = $ogLive->isInstalled();
        $this->isDefault = $ogLive->getIsDefault();
        $this->downloadUrl = $ogLive->getDownloadUrl();
        $this->distribution = $ogLive->getDistribution();
        $this->revision = $ogLive->getRevision();
        $this->filename = $ogLive->getFilename();
        $this->checksum = $ogLive->getChecksum();
        $this->kernel = $ogLive->getKernel();
        $this->architecture = $ogLive->getArchitecture();
        $this->status = $ogLive->getStatus();
        $this->date = $ogLive->getDate();
        $this->createdAt = $ogLive->getCreatedAt();
        $this->createdBy = $ogLive->getCreatedBy();
    }
}