<?php
declare(strict_types=1);

namespace AuxCF\Entities\FieldGroup;

use AuxCF\Entities\Settings\Enum\OperatorEnum;

class FieldGroupLocationEntity
{
  protected string $param;
  protected OperatorEnum $operator = OperatorEnum::EQUALS;
  protected string $value;

  public function __construct() {}

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

  public function setOperator(string|OperatorEnum $operator): self
  {
    if (is_scalar($operator)) {
      $operator = OperatorEnum::tryFromName($operator);
    }

    $this->operator = $operator;

    return $this;
  }

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

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

  public static function create(string $value): static
  {
    $location = new static();
    $location->setValue($value);

    return $location;
  }
}
