<?php
// phpcs:disable WordPress.Security.EscapeOutput, WordPress.WP.I18n
declare(strict_types=1);
namespace Uncanny_Automator\App\Recipe_Builder\Action\Value_Objects;

/**
 * Action ID Value Object.
 *
 * Represents an action identifier - must be positive integer or null.
 * Follows the same pattern as Trigger_Id.
 *
 * @since 7.0.0
 */
class Action_Id {

	private $value;

	/**
	 * Constructor.
	 *
	 * @param mixed $value Action ID value.
	 * @throws \InvalidArgumentException If invalid ID.
	 */
	public function __construct( $value ) {
		$this->validate( $value );
		$this->value = $value;
	}

	/**
	 * Get value.
	 *
	 * @return int|null
	 */
	public function get_value() {
		return $this->value;
	}

	/**
	 * Check if ID is null (new action).
	 *
	 * @return bool
	 */
	public function is_null(): bool {
		return null === $this->value;
	}

	/**
	 * Validate action ID.
	 *
	 * @param mixed $value Value to validate.
	 * @throws \InvalidArgumentException If invalid.
	 */
	private function validate( $value ): void {
		if ( null !== $value && ( ! is_int( $value ) || $value <= 0 ) ) {
			throw new \InvalidArgumentException( 'Action ID must be a positive integer or null' );
		}
	}
}
