<?php

namespace SplitPay\Core;

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

class CurrencyHelper {

	private static array $zeroDecimal = [
		'BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW',
		'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF',
		'XOF', 'XPF',
	];

	private static array $threeDecimal = [
		'BHD', 'JOD', 'KWD', 'OMR', 'TND',
	];

	public static function toStripeAmount( float $total, string $currency ): int {
		$currency = strtoupper( trim( $currency ) );

		if ( in_array( $currency, self::$zeroDecimal, true ) ) {
			return (int) round( $total );
		}

		if ( in_array( $currency, self::$threeDecimal, true ) ) {
			return (int) round( $total * 1000 );
		}

		return (int) round( $total * 100 );
	}
}
