package net.pokeranalytics.android.util

import android.content.Context
import net.pokeranalytics.android.model.realm.Bankroll
import java.text.NumberFormat
import java.util.*

class CurrencyUtils {

	companion object {

		/**
		 * return the currency associated with this bankroll
		 */
		fun getCurrency(bankroll: Bankroll? = null) : Currency {
			val currencyCode = bankroll?.currency?.code ?: Currency.getInstance(Locale.getDefault()).currencyCode
			return Currency.getInstance(currencyCode)
		}

		/**
		 * Get a currency formatter
		 */
		fun getCurrencyFormatter(context: Context, currency: Currency? = null) : NumberFormat {
			val currencyFormatter = NumberFormat.getCurrencyInstance(Preferences.getCurrencyLocale(context))
			currency?.let {
				currencyFormatter.currency = it
			}
			currencyFormatter.minimumFractionDigits = 0
			currencyFormatter.maximumFractionDigits = 2
			return currencyFormatter
		}

	}

}