<?php

declare(strict_types=1);

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

final class CRToday_Source_Selection {
	/**
	 * Parse compound source value (`SOURCE:DEAL`) into canonical keys.
	 *
	 * @return array{sourceId:string,deal:string}
	 */
	public static function parse_compound_source(string $value): array {
		$normalized = strtoupper(trim($value));
		if ($normalized === '') {
			return [
				'sourceId' => 'FEX',
				'deal'     => 'STANDARD',
			];
		}

		if (strpos($normalized, ':') === false) {
			return [
				'sourceId' => $normalized,
				'deal'     => 'STANDARD',
			];
		}

		[$source_id, $deal] = array_map('trim', explode(':', $normalized, 2));

		return [
			'sourceId' => $source_id !== '' ? $source_id : 'FEX',
			'deal'     => $deal !== '' ? $deal : 'STANDARD',
		];
	}
}
