<?php
declare(strict_types=1);

namespace AuxCF\Entities\Field;

use AuxCF\Entities\Field\Enum\FieldTypeEnum;
use AuxCF\Entities\Field\Traits\ChoicesFieldTraits;
use AuxCF\Entities\FieldEntity;
use AuxCF\Entities\Settings\Enum\IntSwitchEnum;
use AuxCF\Entities\Settings\Traits\EnumPropertyTraits;

class CheckboxFieldEntity extends FieldEntity
{
  use ChoicesFieldTraits, EnumPropertyTraits;

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

  protected FieldTypeEnum $type = FieldTypeEnum::Checkbox;

  protected IntSwitchEnum $toggle = IntSwitchEnum::Off;
  protected IntSwitchEnum $allowCustom = IntSwitchEnum::Off;
  protected IntSwitchEnum $saveCustom = IntSwitchEnum::Off;
  protected string $customChoiceButtonText = 'Add new choice';

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

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

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

  public function setCustomChoiceButtonText(string $customChoiceButtonText): self
  {
    $this->customChoiceButtonText = $customChoiceButtonText;
    return $this;
  }

  public function getFieldArray(): array
  {
    $array = [
      'toggle' => $this->toggle->value,
      'allow_custom' => $this->allowCustom->value,
      'save_custom' => $this->saveCustom->value,
      'custom_choice_button_text' => $this->customChoiceButtonText,
    ];

    return $array;
  }
}
