<?php

namespace Clonable\Helpers;

use Clonable\Models\Site;
use Clonable\Services\MultiCurrencyService;

class MultiCurrency
{
    public static function get_currency_by_region(?string $target_region) {
        if (class_exists('WOOMULTI_CURRENCY_Data')) {
            $settings = \WOOMULTI_CURRENCY_Data::get_ins();
            if ($target_region !== null) {
                $target_region_upper = strtoupper($target_region);
                return $settings->get_currency_code($target_region_upper);
            } else {
                return $settings->get_default_currency();
            }
        }

        // Default WooCommerce behaviour
	    if (function_exists('get_woocommerce_currency')) {
		    return get_woocommerce_currency();
	    }
        return null;
    }

    public static function get_all_currencies(): array {
        if (class_exists('WOOMULTI_CURRENCY_Data')) {
            $settings = \WOOMULTI_CURRENCY_Data::get_ins();
            return $settings->get_currencies();
        }

		if (function_exists("get_woocommerce_currencies")) {
			// Default woocommerce currency function
			$currency_map = get_woocommerce_currencies();
			return array_keys($currency_map);
		}
        return [];
    }
}