<?php
declare(strict_types=1);

namespace AuxCF\Entities\Field;

use AuxCF\Entities\Settings\Enum\OperatorEnum;

class ConditionalLogicConditionEntity
{
  protected string $field;
  protected OperatorEnum $operator;
  protected ?string $value;

  public function __construct(string $field, string|OperatorEnum $operator, ?string $value) {
    if (is_scalar($operator)) {
      $operator = OperatorEnum::tryFromName($operator);
    }

    $this->field = $field;
    $this->operator = $operator;
    $this->value = $value;
  }

  public function getArray(): array
  {
    return [
      'field' => $this->field,
      'operator' => $this->operator->value,
      'value' => $this->value,
    ];
  }
}
