<?php

namespace App\Dto\Output;

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

#[Get(shortName: 'ImageImageRepository')]
class ImageImageRepositoryOutput extends AbstractOutput
{
    #[Groups(['image-image-repository:read', 'image:read'])]
    #[ApiProperty(
        description: 'La imagen asociada',
        example: null
    )]
    public ?ImageOutput $image = null;

    #[Groups(['image-image-repository:read', 'image:read'])]
    #[ApiProperty(
        description: 'El repositorio donde está almacenada la imagen',
        example: null
    )]
    public ?ImageRepositoryOutput $imageRepository = null;

    #[Groups(['image-image-repository:read', 'image:read'])]
    #[ApiProperty(
        description: 'El estado de la imagen en el repositorio',
        example: 'synchronized'
    )]
    public string $status;

    #[Groups(['image-image-repository:read', 'image:read', 'partition:read', 'client:read'])]
    #[ApiProperty(
        description: 'El nombre de la imagen',
        example: 'Windows10-v1'
    )]
    public string $name;

    #[Groups(['image-image-repository:read', 'image:read'])]
    #[ApiProperty(
        description: 'La suma de verificación completa de la imagen',
        example: 'a1b2c3d4e5f6...'
    )]
    public ?string $imageFullsum = null;

    #[Groups(['image-image-repository:read', 'image:read'])]
    #[ApiProperty(
        description: 'Información sobre las particiones de la imagen',
        example: []
    )]
    public ?array $partitionInfo = null;

    #[Groups(['image-image-repository:read', 'image:read'])]
    #[ApiProperty(
        description: 'El tamaño de los datos en bytes',
        example: '10737418240'
    )]
    public ?string $datasize = null;

    #[Groups(['image-image-repository:read', 'image:read'])]
    #[ApiProperty(
        description: 'La descripción de la imagen',
        example: 'Imagen base de Windows 10 actualizado'
    )]
    public ?string $description = null;

    #[Groups(['image:read', 'image-image-repository:read'])]
    #[ApiProperty(
        description: 'La versión de la imagen',
        example: 1
    )]
    public ?int $version = null;

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

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

    public function __construct(ImageImageRepository $imageImageRepository, array $context = [])
    {
        parent::__construct($imageImageRepository);

        if (isset($context['groups']) && in_array('image-image-repository:read', $context['groups'])) {
            if ($imageImageRepository->getImage()) {
                $this->image = new ImageOutput($imageImageRepository->getImage());
            }
        }

        if ($imageImageRepository->getRepository()) {
            $this->imageRepository = new ImageRepositoryOutput($imageImageRepository->getRepository());
        }

        $this->name = $imageImageRepository->getName();
        $this->version = $imageImageRepository->getVersion();
        $this->partitionInfo = json_decode($imageImageRepository->getPartitionInfo(), true);
        $this->status = $imageImageRepository->getStatus();
        $this->imageFullsum = $imageImageRepository->getImageFullsum();
        $this->datasize = $imageImageRepository->getDatasize();
        $this->description = $imageImageRepository->getDescription();
        $this->createdAt = $imageImageRepository->getCreatedAt();
        $this->createdBy = $imageImageRepository->getCreatedBy();
    }
}