<?php
declare(strict_types=1);

namespace AuxCF\Entities\FieldGroup;

use AuxCF\Entities\Settings\Enum\OperatorEnum;

class FieldGroupLocationsSetEntity
{
  /**
   * @var FieldGroupLocationEntity[]
   */
  protected $locations = [];

  public function __construct() {}

  public function addLocation(string|FieldGroupLocationEntity $param, string|OperatorEnum $operator = null, string $value = null): void
  {
    if (is_a($param, FieldGroupLocationEntity::class)) {
      $location = $param;
    } else {
      $location = new FieldGroupLocationEntity($param, $operator, $value);
    }

    $this->locations[] = $location;
  }

  public function getSetArray(): array
  {
    $array = [];

    foreach ($this->locations as $location) {
      $array[] = $location->getArray();
    }

    return $array;
  }
}
