<?php

declare(strict_types=1);

namespace LolaCore\Marketing;

/**
 * Builds outbound lolacore.com URLs with consistent UTM parameters.
 */
class MarketingUrlBuilder {

	public const SOURCE = 'plugin';

	public const MEDIUM_SETTINGS_EXPANSIONS = 'settings_expansions';
	public const MEDIUM_SUBMENU_ADDONS      = 'submenu_addons';
	public const MEDIUM_PLUGINS_ROW         = 'plugins_row';

	/**
	 * Append standard UTM query args to a marketing URL.
	 *
	 * @param string $baseUrl  Absolute URL without conflicting utm_* params.
	 * @param string $medium   utm_medium value.
	 * @param string $campaign utm_campaign value.
	 */
	public static function build( string $baseUrl, string $medium, string $campaign ): string {
		$params = [
			'utm_source'   => self::SOURCE,
			'utm_medium'   => $medium,
			'utm_campaign' => $campaign,
		];

		$separator = str_contains( $baseUrl, '?' ) ? '&' : '?';

		return $baseUrl . $separator . http_build_query( $params, '', '&', PHP_QUERY_RFC3986 );
	}
}
