using System;
using System.Globalization;
using System.Linq;

namespace Mox.Shared.Math
{
	public class Color : IEquatable<Color>
	{
		public Color(float _fR, float _fG, float _fB, float _fA)
		{
			R = _fR;
			G = _fG;
			B = _fB;
			A = _fA;
		}

		public override string ToString()
		{
			return string.Join(", ", (new [] { R, G, B, A}).Select(c => c.ToString(CultureInfo.InvariantCulture)));
		}

		public float R;
		public float G;
		public float B;
		public float A;

		public bool Equals(Color other)
		{
			if (ReferenceEquals(null, other))
			{
				return false;
			}

			if (ReferenceEquals(this, other))
			{
				return true;
			}

			return R.Equals(other.R) && G.Equals(other.G) && B.Equals(other.B) && A.Equals(other.A);
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj))
			{
				return false;
			}

			if (ReferenceEquals(this, obj))
			{
				return true;
			}

			if (obj.GetType() != GetType())
			{
				return false;
			}

			return Equals((Color) obj);
		}

		public override int GetHashCode()
		{
			unchecked
			{
				var hashCode = R.GetHashCode();
				hashCode = (hashCode * 397) ^ G.GetHashCode();
				hashCode = (hashCode * 397) ^ B.GetHashCode();
				hashCode = (hashCode * 397) ^ A.GetHashCode();

				return hashCode;
			}
		}
	}
}
