using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text.RegularExpressions;

namespace digioz
{
    public class WebLink
    {
        public WebLink()
        { 
        }

        /// <summary>
        /// Used to construct WebLink object. 
        /// Will only be used when information 
        /// for the parameters are retrieved 
        /// from Datastore.
        /// </summary>
        /// <param name="piId">Id</param>
        /// <param name="psName">Name</param>
        /// <param name="psUrl">Url</param>
        /// <param name="psDetail">Detail</param>
        /// <param name="psCategory">Category</param>
        /// <param name="psUpdated">Updated On</param>
        /// <param name="psAdded">Added On</param>
        /// <param name="psStatus">Status</param>
        public WebLink(int piId, string psName, string psUrl, string psDetail, string psCategory, string psUpdated, string psAdded, short psStatus)
        {
            //validating the inputs
            if (psName.Length > 100)
            {
                throw new ArgumentException("Name can't be longer than 100 characters", "psName");
            }
            if (psName.Length < 1)
            {
                throw new ArgumentException("Name can't be empty", "psName");
            }
            if (!coUrlValidation.Match(psUrl).Success)
            {
                throw new ArgumentException("The Url is not valid", "psUrl");
            }
            if (psStatus < 0 || Convert.ToInt32(psStatus) > 2)
            {
                throw new ArgumentException("Status can have only 0, 1 or 2 as a value");
            }

            //on successful validation
            ciId = piId;
            csName = psName;
            csUrl = psUrl;
            csDetail = psDetail;
            csCategory = psCategory;
            csUpdated = psUpdated;
            csAdded = psAdded;
            if (psStatus == 0)
            {
                csStatus = "Pending";
            }
            if (psStatus == 1)
            {
                csStatus = "Active";
            }
            if (psStatus == 2)
            {
                csStatus = "Deleted";
            }
        }

        #region All Private properties
        private int ciId;
        private string csName;
        private string csUrl;
        private string csDetail;
        private string csCategory;
        private string csUpdated;
        private string csAdded;
        private string csStatus;
        private Regex coUrlValidation = new Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
        #endregion

        #region All Public Attributes

        /// <summary>
        /// A unique ID of the link
        /// </summary>
        public string ID
        { get { return ciId.ToString(); } }

        /// <summary>
        /// Name of the Link
        /// </summary>
        public string Name
        { get { return csName; } }

        /// <summary>
        /// Url of the Link
        /// </summary>
        public string Url
        { get { return csUrl; } }

        /// <summary>
        /// Detail of the Link
        /// </summary>
        public string Detail
        { get { return csDetail; } }

        /// <summary>
        /// Category, this Link Belongs to
        /// </summary>
        public string Category
        { get { return csCategory; } }

        /// <summary>
        /// Date and time when this link was updated
        /// </summary>
        public string UpdatedOn
        { get { return csUpdated; } }

        /// <summary>
        /// Date and time when this link was added
        /// </summary>
        public string AddedOn
        { get { return csAdded; } }

        /// <summary>
        /// Status of the link which can be 0, 1 or 2 representing 'Active', 'Pending' and 'Deleted' respectively.
        /// </summary>
        public string Status
        { get { return csStatus; } }

        #endregion
    }
}
