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

using System;
using System.Collections;
using CommunityServer;
using CommunityServer.Components;

namespace CommunityServer
{
	/// <summary>
	/// Summary description for UserInvitations.
	/// </summary>
	public class UserInvitations
	{
		private UserInvitations()
		{
		}

		public static void Accept(UserInvitation invite, User userAccepted)
		{
			CSEvents.AcceptUserInvitation(invite, userAccepted);
			Delete(invite.InvitationKey);
		}

		public static UserInvitation GetUserInvitation(Guid invitationKey) 
		{
			// Create Instance of the IDataProvider
			CommonDataProvider dp = CommonDataProvider.Instance();

			// Get the current user
			return dp.GetUserInvitation(invitationKey);
		}

		public static void Create(UserInvitation invite)
		{
			// Create Instance of the IDataProvider
			CommonDataProvider dp = CommonDataProvider.Instance();

            CSEvents.BeforeUserInvitation(invite, ObjectState.Create);

			dp.CreateUserInvitation(invite);

			Emails.UserInvitation(invite);

			CSEvents.AfterUserInvitation(invite, ObjectState.Create);
		}

		public static void Delete(Guid invitationKey)
		{
			UserInvitation invite = GetUserInvitation(invitationKey);
			if (invite != null)
				Delete(invite);
		}

		public static void Delete(UserInvitation invite)
		{
			// Create Instance of the IDataProvider
			CommonDataProvider dp = CommonDataProvider.Instance();

			CSEvents.BeforeUserInvitation(invite, ObjectState.Delete);

			dp.DeleteUserInvitation(invite.InvitationKey);

			CSEvents.AfterUserInvitation(invite, ObjectState.Delete);
		}

		public static void Expire(DateTime expirationDate)
		{
			// Create Instance of the IDataProvider
			CommonDataProvider dp = CommonDataProvider.Instance();

			dp.ExpireUserInvitations(expirationDate);
		}

		public static ArrayList GetUserInvitationsBeforeDate(DateTime dateInvited)
		{
			// Create Instance of the IDataProvider
			CommonDataProvider dp = CommonDataProvider.Instance();

			return dp.GetUserInvitationsBeforeDate(dateInvited);
		}

		public static ArrayList GetUserInvitationsForUser(int userID)
		{
			// Create Instance of the IDataProvider
			CommonDataProvider dp = CommonDataProvider.Instance();

			return dp.GetUserInvitationsForUser(userID);
		}
	}
}
