<?php
declare(strict_types=1);

namespace AuxCF\Entities\Field;

use AuxCF\Entities\Field\Enum\FieldTypeEnum;
use AuxCF\Entities\Field\Enum\PostFieldReturnFormatEnum;
use AuxCF\Entities\Field\Enum\TaxonomyFieldReturnFormatEnum;
use AuxCF\Entities\Field\Enum\TaxonomyFieldTypeEnum;
use AuxCF\Entities\Field\Traits\AllowNullTraits;
use AuxCF\Entities\FieldEntity;
use AuxCF\Entities\Settings\Enum\IntSwitchEnum;
use AuxCF\Entities\Settings\Traits\EnumPropertyTraits;

class PostFieldEntity extends FieldEntity
{
  use AllowNullTraits, EnumPropertyTraits;

  protected static array $arrayPropertiesMethods = [
    'getAllowNullArray',
  ];

  protected FieldTypeEnum $type = FieldTypeEnum::Post;

  protected array $postType = [];
  protected array $postStatus = [];
  protected PostFieldReturnFormatEnum $returnFormat = PostFieldReturnFormatEnum::Id;
  protected IntSwitchEnum $multiple = IntSwitchEnum::Off;

  public function setPostType(array $postType): self
  {
    $this->postType = $postType;
    return $this;
  }

  public function setPostStatus(array $postStatus): self
  {
    $this->postStatus = $postStatus;
    return $this;
  }

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

  public function setMultiple(int|IntSwitchEnum $multiple): self
  {
    $this->setEnumProperty(IntSwitchEnum::class, $multiple, 'multiple');
    return $this;
  }

  public function getFieldArray(): array
  {
    $array = [
      'return_format' => $this->returnFormat->value,
      'taxonomy' => '',
      'post_type' => $this->postType,
      'post_status' => $this->postStatus,
      'multiple' => $this->multiple->value,
      'ui' => 1,
      'bidirectional' => 0,
      'bidirectional_target' => [],
    ];

    return $array;
  }
}
