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

using System;
using System.Net;
using CommunityServer.Components;
using Rss;

namespace CommunityServer.Reader.Components
{
	/// <summary>
	/// Summary description for Feed.
	/// </summary>
	public class Feed
	{

		#region Private Members

		private int _folderFeedId;
		private int _feedId = 0;
		private string _url;
		private string _title;
		private string _link;
		private string _language;
		private string _generator;
		private DateTime _subscribeDate;
		private DateTime _lastUpdateDate;
        private DateTime _lastModified;
        private string _etag;
		private CommunityServer.Reader.Components.FeedState _feedState;
		private int _feedStateId;
		private int _unreadCount;
		private string _stateName;
		private string _stateDescription;
		private int _subscribeCount;
		private int _postCount;

		#endregion

		#region Constructor(s)

		public Feed()
		{
		
			_lastUpdateDate = DateTime.Now;
			_subscribeDate = DateTime.Now;
            _lastModified = DateTime.Now;

		}

		#endregion

		#region Methods


        public HttpWebRequest CreateRequest()
        {
            HttpWebRequest request = CSRequest.CreateRequest(this.Url);
            if(!IsNew)
            {
                request.IfModifiedSince = this.LastModified;
                request.Headers.Add("If-None-Match", this.ETag);
            }
            return request;
        }


		#endregion

		#region Properties

		public int FolderFeedId
		{
			get { return _folderFeedId; }
			set { _folderFeedId = value; }
		}

		public int FeedId
		{
			get { return _feedId; }	
			set { _feedId = value; }
		}

		public string Url
		{
			get { return _url; }	
			set { _url = value; }
		}

        public string ETag
        {
            get { return _etag; }	
            set { _etag = value; }
        }

		public string Title
		{
			get { return _title; }	
			set { _title = value; }
		}

		public string Link
		{
			get { return _link; }
			set { _link = value; }
		}

		public string Language
		{
			get { return _language; }
			set { _language = value; }
		}

		public string Generator
		{
			get { return _generator; }
			set { _generator = value; }
		}

		public DateTime SubscribeDate
		{
			get { return _subscribeDate; }
			set { _subscribeDate = value; }
		}

		public DateTime LastUpdateDate
		{
			get { return _lastUpdateDate; }	
			set { _lastUpdateDate = value; }
		}

        public DateTime LastModified
        {
            get { return _lastModified; }	
            set { _lastModified = value; }
        }

		public CommunityServer.Reader.Components.FeedState FeedState
		{
			get { return _feedState; }	
			set { _feedState = value; }
		}

		public int FeedStateId
		{
			get { return _feedStateId; }	
			set { _feedStateId = value; }
		}

		public int UnreadCount
		{
			get { return _unreadCount; }
			set { _unreadCount = value; }
		}

		public string StateName
		{
			get { return _stateName; }
			set { _stateName = value; }
		}

		public string StateDescription
		{
			get { return _stateDescription; }
			set { _stateDescription = value; }
		}

		public int SubscribeCount
		{
			get { return _subscribeCount; }
			set { _subscribeCount = value; }
		}

		public int PostCount
		{
			get { return _postCount; }
			set { _postCount = value; }
		}

        protected bool IsNew
        {
            get { return this.FeedId == 0;}
        }

		#endregion



	}
}
