<?php
declare(strict_types=1);

namespace AuxCF\Entities\Field\Traits;

use AuxCF\Entities\Field\Enum\ImageFieldLibraryEnum;
use AuxCF\Entities\Field\Enum\ImageFieldPreviewSizeEnum;
use AuxCF\Entities\Field\Enum\ImageFieldReturnFormatEnum;
use AuxCF\Entities\Settings\Traits\EnumPropertyTraits;

trait FileTraits
{
  use EnumPropertyTraits;

  protected ImageFieldReturnFormatEnum $returnFormat = ImageFieldReturnFormatEnum::DEFAULT;
  protected ImageFieldLibraryEnum $library = ImageFieldLibraryEnum::DEFAULT;
  protected ImageFieldPreviewSizeEnum $previewSize = ImageFieldPreviewSizeEnum::DEFAULT;

  protected int|string $minSize = 0;
  protected int|string $maxSize = 0;
  /**
   * @var string Comma separated list of file type extensions allowed when uploading.
   */
  protected string $mimeTypes = '';

  public function setReturnFormat(string|ImageFieldReturnFormatEnum $returnFormat): self
  {
    $this->setEnumProperty(ImageFieldReturnFormatEnum::class, $returnFormat, 'returnFormat');
    return $this;
  }

  public function setLibrary(string|ImageFieldLibraryEnum $library): self
  {
    $this->setEnumProperty(ImageFieldLibraryEnum::class, $library, 'library');
    return $this;
  }

  public function setPreviewSize(string|ImageFieldPreviewSizeEnum $previewSize): self
  {
    $this->setEnumProperty(ImageFieldPreviewSizeEnum::class, $previewSize, 'previewSize');
    return $this;
  }

  public function getFileArray(): array
  {
    $array = [
      'min_size' => $this->minSize,
      'max_size' => $this->maxSize,
      'return_format' => $this->returnFormat->value,
      'library' => $this->library->value,
      'preview_size' => $this->previewSize->value,
      'mime_types' => $this->mimeTypes,
    ];

    return $array;
  }
}
