using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class YearRange : IEquatable<int>, IComparable<YearRange>
{
	public int FromYear { get; set; }

	public int ToYear { get; set; }

	public int Year { get; set; }

	public override string ToString()
	{
		if (FromYear == ToYear)
			return FromYear.ToString();

		return FromYear + "-" + ToYear;
	}

	#region Equals, GetHashCode
	public override bool Equals(object obj)
	{
		var other = (YearRange)obj;

		return other.Year >= FromYear && other.Year <= ToYear;
	}

	public override int GetHashCode()
	{
		return FromYear * ToYear;
	}

	public bool Equals(int other)
	{
		return FromYear >= other && other <= ToYear;
	}

	#endregion

	#region IComparable<YearRange>
	public int CompareTo(YearRange other)
	{
		return this.FromYear.CompareTo(other.FromYear);
	}
	#endregion

	#region Comparison operators override

	public static bool operator <(YearRange left, YearRange right)
	{
		return left.FromYear < right.FromYear;
	}

	public static bool operator <=(YearRange left, YearRange right)
	{
		return left.FromYear <= right.FromYear;
	}

	public static bool operator >(YearRange left, YearRange right)
	{
		return left.FromYear > right.FromYear;
	}

	public static bool operator >=(YearRange left, YearRange right)
	{
		return left.FromYear >= right.FromYear;
	}
	#endregion
}
