using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace Betfair.Gamex.API.UberClient.Classes
{
	/// <summary>
	/// Summary description for util.
	/// </summary>
	public class Util
	{
        /// <summary>
        /// Constructor
        /// </summary>
        public Util()
        {
        }

        /// <summary>
        /// Returns true if specificString is in stringGroup
        /// </summary>
        /// <param name="specificString">Target string being tested against the array of strings stringGroup</param>
        /// <param name="stringGroup">Array of strings to be compared</param>
        /// <param name="ignoreCase">true if case sensitivity ignored</param>
        /// <returns>true or false</returns>
        public static int ArrayIndexOf(string specificString, string[] stringGroup, bool ignoreCase)
        {
            int index = -1;
            for (int i = 0; i < stringGroup.Length; i++)
            {
                if (String.Compare(specificString, stringGroup[i], ignoreCase) == 0)
                {
                    index = i;
                    break;
                }
            }

            return (index);
        }

        public static string FormatMoney(double amount)
        {
            return (String.Format(((amount < 1000) ? "{0:0.00}" : "{0:0,000.00}"), amount));
        }

        public static string FormatOdds(double odds)
        {
            string s = String.Format("{0:0.00}", odds);

            if (s.IndexOf("0", s.Length - 1) > -1)
            {
                s = s.Substring(0, s.Length - 1);
            }

            return (s);
        }

        public static string ParseNumericValue(string dirty)
        {
            string numeric = string.Empty;
            for (int i = 0; i < dirty.Length; i++)
            {
                if ("0123456789.,".IndexOf(dirty.Substring(i, 1)) > -1)
                {
                    numeric = String.Format("{0}{1}", numeric, dirty.Substring(i, 1));
                }
            }

            if (numeric.Length == 0)
            {
                numeric = "0";
            }

            return (numeric);
        }

        /// <summary>
        /// Gets the colour of the status label
        /// </summary>
        /// <returns></returns>
        public static Color GetStatusColour(string status)
        {
            switch (status.ToLower())
            {
                case "winner":
                    return Color.Green;
                case "loser":
                    return Color.Red;
                default:
                    return Color.Gray;
            }
        }
    }
}
