<?php
declare(strict_types=1);

namespace AuxCF\Entities\Settings\Traits;

/**
 * Utilities for working with enumerated properties in an ACF field entity
 * @since 1.0.0
 */
trait EnumPropertyTraits
{
  /**
   * Set a property to an enumerated value. If an invalid property value is provided, the property will not be set.
   * @since 1.0.0
   */
  protected function setEnumProperty(string $enum, int|string|\UnitEnum $value, string $property) {
    if (is_scalar($value)) {
      $value = $enum::tryFromName($value);
    }

    if ($value) {
      $this->{$property} = $value;
    }
  }
}
