<?php

namespace App\Dto\Output;

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

#[Get(shortName: 'Partition')]
class PartitionOutput extends AbstractOutput
{
    #[Groups(['partition:read', 'client:read'])]
    public ?int $diskNumber = null;

    #[Groups(['partition:read', 'client:read'])]
    public ?int $partitionNumber = null;

    #[Groups(['partition:read', 'client:read'])]
    public ?string $partitionCode = null;

    #[Groups(['partition:read', 'client:read'])]
    public ?int $size = null;

    #[Groups(['partition:read', 'client:read'])]
    public ?string $cacheContent = null;

    #[Groups(['partition:read', 'client:read'])]
    public ?string $filesystem = null;

    #[Groups(['partition:read', 'client:read'])]
    public ?OperativeSystemOutput $operativeSystem = null;

    #[Groups(['partition:read', 'client:read'])]
    public ?ImageImageRepositoryOutput $image = null;

    #[Groups(['partition:read', 'client:read'])]
    public ?int $memoryUsage = null;

    public function __construct(Partition $partition)
    {
        parent::__construct($partition);

        $this->diskNumber = $partition->getDiskNumber();
        $this->partitionNumber = $partition->getPartitionNumber();
        $this->partitionCode = $partition->getPartitionCode();
        $this->size = $partition->getSize() / 1024 ;
        $this->cacheContent = $partition->getCacheContent();
        $this->filesystem = $partition->getFilesystem();

        if ($partition->getOperativeSystem()) {
            $this->operativeSystem = new OperativeSystemOutput($partition->getOperativeSystem());
        }

        if ($partition->getImage()) {
            $this->image = new ImageImageRepositoryOutput($partition->getImage());
        }

        $this->memoryUsage = $partition->getMemoryUsage() / 100;
    }
}