<?php
/**
 * This file is part of the Wisewand WordPress plugin.
 *
 * @package Wisewand
 * @since 1.0.0
 * @license GPL-2.0-or-later
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */
namespace Wisewand\Utils;

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Maps DataForSEO location codes to Wisewand country codes
 */
class Location_Mapper {

	/**
	 * Map location_code (DataForSEO) to country code (Wisewand API)
	 *
	 * @param int $location_code DataForSEO location code
	 * @return string Wisewand country code
	 */
	public static function location_to_country( $location_code ) {
		$mapping = array(
			2250 => 'fr',  // France
			2840 => 'us',  // United States
			2826 => 'gb',  // United Kingdom
			2124 => 'ca',  // Canada
			2276 => 'de',  // Germany
			2724 => 'es',  // Spain
			2380 => 'it',  // Italy
			2056 => 'be',  // Belgium
			2756 => 'ch',  // Switzerland
		);

		return $mapping[ $location_code ] ?? 'us';
	}

	/**
	 * Get language code from location code
	 *
	 * @param int $location_code DataForSEO location code
	 * @return string Language code
	 */
	public static function location_to_language( $location_code ) {
		$mapping = array(
			2250 => 'fr',  // France
			2840 => 'en',  // United States
			2826 => 'en',  // United Kingdom
			2124 => 'en',  // Canada (English)
			2276 => 'de',  // Germany
			2724 => 'es',  // Spain
			2380 => 'it',  // Italy
			2056 => 'fr',  // Belgium (French)
			2756 => 'fr',  // Switzerland (French)
		);

		return $mapping[ $location_code ] ?? 'en';
	}
}
