//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;

namespace CommunityServer.Components 
{
	/// <summary>
	/// A hyperlink displayed in a blog link category
	/// </summary>
	public class Link : IComparable
	{

		#region Properties

		public Int32 LinkID {
			get {
				return _linkID;
			}
			set {
				_linkID = value;
			}
		}
		private Int32 _linkID;

		public Int32 LinkCategoryID {
			get {
				return _linkCategoryID;
			}
			set {
				_linkCategoryID = value;
			}
		}
		private Int32 _linkCategoryID;

		public String Title {
			get {
				return _title;
			}
			set {
				_title = value;
			}
		}
		private String _title;

		public String Url {
			get {
				return _url;
			}
			set {
				_url = value;
			}
		}
		private String _url;

		public Boolean IsEnabled {
			get {
				return _isEnabled;
			}
			set {
				_isEnabled = value;
			}
		}
		private Boolean _isEnabled;

		public Int32 SortOrder {
			get {
				return _sortOrder;
			}
			set {
				_sortOrder = value;
			}
		}
		private Int32 _sortOrder = 0;

		public String Rel
		{
			get 
			{
				return _rel;
			}
			set 
			{
				_rel = value;
			}
		}
		private String _rel;

		public String Description
		{
			get 
			{
				return _description;
			}
			set 
			{
				_description = value;
			}
		}
		private String _description;

		private DateTime _dateCreated;

		public DateTime DateCreated
		{
			get{return _dateCreated;}
			set{_dateCreated = value;}
		}

		#endregion


		#region Constructor

		public Link() 
		{ }

		#endregion

		#region IComparable Members

		private LinkSortBy _sortBy = LinkSortBy.Title;
		private CommunityServer.Components.SortOrder _linkSortOrder = CommunityServer.Components.SortOrder.Ascending;

		public LinkSortBy SortBy
		{
			set{ _sortBy = value;}
		}

		public CommunityServer.Components.SortOrder LinkSortOrder
		{
			set{ _linkSortOrder = value;}
		}

		public int CompareTo(object obj)
		{
			Link link = obj as Link;
			if(link != null)
			{
				switch(link._sortBy)
				{
					case LinkSortBy.Date:

						if(link._linkSortOrder == CommunityServer.Components.SortOrder.Ascending)
						{
							return this.DateCreated.CompareTo(link.DateCreated);
						}
						else
						{
							return link.DateCreated.CompareTo(this.DateCreated);
						}

					case LinkSortBy.Title:

						if(link._linkSortOrder == CommunityServer.Components.SortOrder.Ascending)
						{
							return this.Title.CompareTo(link.Title);
						}
						else
						{
							return link.Title.CompareTo(this.Title);
						}

					default:

						if(link._linkSortOrder == CommunityServer.Components.SortOrder.Ascending)
						{
							return this._sortOrder.CompareTo(link.SortOrder);
						}
						else
						{
							return link.SortOrder.CompareTo(this._sortOrder);
						};
				}
			}
	
			throw new ArgumentException("Specified object is not of type Link");
		}

	
		public enum LinkSortBy
		{
			SortOrder,
			Title,
			Date
		}

		#endregion
	}

	
}
