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


using System;
using CommunityServer.Components;

namespace CommunityServer.Discussions.Components {
    
    public class PrivateForum : Forum
    {
        public PrivateForum() : base(0)
		{
			this.ApplicationType = ApplicationType.Forum;
		}


        public override bool IsPrivate
        {
            get
            {
                return true;
            }
        }




    }
    
    /// <summary>
    /// This class defines the properties that makeup a forum.
    /// </summary>
    public class Forum : Section {

        public Forum() { }

        public Forum(int forumID) : this() { SectionID = forumID; }

        public override string Url
        {
            get { return ForumUrls.Instance().Forum(this.SectionID);}
        }

        #region Properties

        public override PermissionBase DefaultRolePermission
        {
            get
            {
                return new ForumPermission();
            }
        }

        public override AccessCheckDelegate AccessCheck
        {
            get
            {
                return new AccessCheckDelegate(ForumPermission.AccessCheck);
            }
        }

        public override ValidatePermissionsDelegate ValidatePermissions
        {
            get
            {
                return new ValidatePermissionsDelegate(ForumPermission.Validate);
            }
        }

        public override PermissionBase OwnerPermission
        {
            get { throw new NotImplementedException(); }
        }

        protected override bool IsOwner(User user)
        {
            return false;
        }

        public override bool IsPrivate
        {
            get
            {
                User user = Users.GetAnonymousUser(true);
                if(user != null)
                {
                    return !Permissions.ValidatePermissions(this,Permission.View|Permission.Read,user);
                }
                return true;
            }

        }

        /// <summary>
        /// Set the default value of ThreadStatus for any new thread.
        /// EnableThreadStatus should be true to have this in effect.
        /// </summary>
        public ThreadStatus DefaultThreadStatusValue {
            
            get {
                try {
                    return (ThreadStatus) int.Parse( GetExtendedAttribute( "DefaultThreadStatusValue" ) ); 
                } 
                catch {
                    return ThreadStatus.NotSet;
                }
            }
            set {
                SetExtendedAttribute( "DefaultThreadStatusValue", ((int) value).ToString() );
            }
        }

        #endregion
    }
}
