<?php

declare(strict_types=1);

namespace App\ApiResources\Core\File;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use App\Enum\Core\FileTypeEnum;
use App\Enum\Core\FileVisibilityEnum;
use App\State\Processor\Core\UploadRequestProcessor;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * A request to upload the given content to a File.
 */
#[ApiResource(
    operations: [
        new Post(
            uriTemplate: '/upload',
            requirements: ['id' => '\\d+'],
            security: 'is_granted("ROLE_FILE")',
            processor: UploadRequestProcessor::class
        ),
    ]
)]
class Upload
{
    #[ApiProperty(identifier: true)]
    private ?int $fileId = null;

    /**
     * Le nom du fichier.
     */
    private string $filename;

    /**
     * Le contenu du fichier uploadé encodé au format Base64.
     */
    private string $content;

    /**
     * Si vrai, le propriétaire du fichier ne sera pas l'utilisateur en cours, mais l'organisation à laquelle il
     * appartient.
     */
    private bool $organizationOwned = false;

    /**
     * Le type de fichier uploadé, si connu.
     */
    #[Assert\Type(type: FileTypeEnum::class)]
    private FileTypeEnum $type = FileTypeEnum::NONE;

    /**
     * Visibilité du fichier.
     */
    #[Assert\Type(type: FileVisibilityEnum::class)]
    private FileVisibilityEnum $visibility = FileVisibilityEnum::NOBODY;

    /**
     * Type mime (il sera déduit automatiquement du nom du fichier s'il n'est pas fourni ici).
     */
    private ?string $mimeType = null;

    /**
     * Configuration du fichier (par exemple le cropping d'une image).
     */
    private ?string $config = null;

    public function getFileId(): int
    {
        return $this->fileId;
    }

    public function setFileId(int $id): self
    {
        $this->fileId = $id;

        return $this;
    }

    public function getContent(): string
    {
        return $this->content;
    }

    public function setContent(string $content): void
    {
        $this->content = $content;
    }

    public function isOrganizationOwned(): bool
    {
        return $this->organizationOwned;
    }

    public function setOrganizationOwned(bool $organizationOwned): self
    {
        $this->organizationOwned = $organizationOwned;

        return $this;
    }

    public function getFilename(): string
    {
        return $this->filename;
    }

    public function setFilename(string $filename): self
    {
        $this->filename = $filename;

        return $this;
    }

    public function getType(): FileTypeEnum
    {
        return $this->type;
    }

    public function setType(FileTypeEnum $type): self
    {
        $this->type = $type;

        return $this;
    }

    public function getVisibility(): FileVisibilityEnum
    {
        return $this->visibility;
    }

    public function setVisibility(FileVisibilityEnum $visibility): self
    {
        $this->visibility = $visibility;

        return $this;
    }

    public function getMimeType(): ?string
    {
        return $this->mimeType;
    }

    public function setMimeType(?string $mimeType): self
    {
        $this->mimeType = $mimeType;

        return $this;
    }

    public function getConfig(): ?string
    {
        return $this->config;
    }

    public function setConfig(?string $config): self
    {
        $this->config = $config;

        return $this;
    }
}
