<?php
/**
 * DataLayer Tracking Provider
 *
 * Routes all tracking events to window.dataLayer via DataLayerQueue.
 * Always considered "configured" — no settings or credentials required.
 * Events are consumed by whatever GTM container or gtag.js is present on
 * the site.
 *
 * @package AmbassadorHub\Tracking\Providers
 */

namespace AmbassadorHub\Tracking\Providers;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use AmbassadorHub\Tracking\DataLayerQueue;
use AmbassadorHub\Tracking\TrackingEvent;
use AmbassadorHub\Tracking\TrackingProviderInterface;

/**
 * Queues events for dataLayer output on the next frontend page render.
 */
final class DataLayerProvider implements TrackingProviderInterface {

	private const PROVIDER_ID = 'dataLayer';

	/**
	 * {@inheritdoc}
	 */
	public function get_id(): string {
		return self::PROVIDER_ID;
	}

	/**
	 * {@inheritdoc}
	 *
	 * Always returns true — no credentials or settings required.
	 */
	public function is_configured(): bool {
		return true;
	}

	/**
	 * {@inheritdoc}
	 */
	public function track( TrackingEvent $event ): void {
		DataLayerQueue::push( $event );
	}

	/**
	 * Filter callback: append this provider to the providers array.
	 *
	 * Usage: add_filter( 'ambh_tracking_providers', [ DataLayerProvider::class, 'register' ] );
	 *
	 * @param TrackingProviderInterface[] $providers
	 *
	 * @return TrackingProviderInterface[]
	 */
	public static function register( array $providers ): array {
		$providers[] = new self();
		return $providers;
	}
}
