<?php
declare(strict_types=1);

namespace App\ApiResources\Export;

use ApiPlatform\Metadata\ApiProperty;
use Symfony\Component\Validator\Constraints as Assert;
use App\Enum\Export\ExportFormatEnum;

/**
 * Demande d'export d'un fichier
 * -- C'est la classe de base des ressources de type ExportRequest --
 */
abstract class ExportRequest
{
    /**
     * Id 'bidon' ajouté par défaut pour permettre la construction
     * de l'IRI par api platform
     *
     * @var int
     */
    #[ApiProperty(identifier: true)]
    protected int $id = 0;

    /**
     * Format de sortie attendu (pdf, txt...)
     * @var string
     */
    #[Assert\Choice(callback: [ExportFormatEnum::class, 'toArray'], message: 'invalid-output-format')]
    protected string $format;

    /**
     * The id of the access requesting this export
     * @var int|null
     */
    protected ?int $requesterId = null;

    /**
     * Should the export be asynchrone
     * @var bool
     */
    protected bool $async = true;

    /**
     * The id of the db record of the file
     * @var int|null
     */
    protected ?int $fileId = null;

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getFormat(): string
    {
        return $this->format;
    }

    /**
     * @param string $format
     */
    public function setFormat(string $format): void
    {
        $this->format = $format;
    }

    /**
     * @return int|null
     */
    public function getRequesterId(): ?int
    {
        return $this->requesterId;
    }

    /**
     * @param int|null $requesterId
     */
    public function setRequesterId(?int $requesterId): void
    {
        $this->requesterId = $requesterId;
    }

    /**
     * @return bool
     */
    public function isAsync(): bool
    {
        return $this->async;
    }

    /**
     * @param bool $async
     */
    public function setAsync(bool $async): void
    {
        $this->async = $async;
    }

    /**
     * @return int|null
     */
    public function getFileId(): ?int
    {
        return $this->fileId;
    }

    /**
     * @param int|null $fileId
     */
    public function setFileId(?int $fileId): void
    {
        $this->fileId = $fileId;
    }
}
