using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Reflection;
using JuSNS.Model;

namespace JuSNS.Factory
{
    public interface IBlog
    {
        #region 前台会员用户
        /// <summary>
        /// 取得某条日志或草稿
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="isdraft"></param>
        /// <returns></returns>
        BlogInfo GetBlog(int blogid, bool isdraft);
        /// <summary>
        /// 发表新日志或草稿
        /// </summary>
        /// <param name="info"></param>
        /// <param name="isdraft">是不是草稿</param>
        /// <returns></returns>
        int Deliver(BlogInfo info, bool isdraft);
        /// <summary>
        /// 修改日志或草稿
        /// </summary>
        /// <param name="info"></param>
        /// <param name="draftSate">0保存日志，1保存草稿，2本来是草稿-保存为日志</param>
        /// <returns></returns>
        int Edit(BlogInfo info, int draftSate);
        /// <summary>
        /// 对日志发表评论
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="userid"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        int CommentsBlog(int blogid, int userid, string content);
        /// <summary>
        /// 删除日志评论,只有评论者或日志发表者可删除
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="commentid"></param>
        /// <returns></returns>
        int DelComment(int userid, int commentid);
        /// <summary>
        /// 删除日志
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="blogid"></param>
        /// <returns></returns>
        int DelBlog(int userid, int blogid, bool isAdmin);

        int Rec(int t, int blogId);
        /// <summary>
        /// 发表草稿
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="draftid"></param>
        /// <returns></returns>
        int DeliverDraft(int userid, int draftid);
        /// <summary>
        /// 删除草稿
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="draftid"></param>
        /// <returns></returns>
        int DelDraft(int userid, int draftid);

        /// <summary>
        /// 返回日志的所有信息
        /// </summary>
        /// <param name="userId">登录用户ID</param>
        /// <param name="blogId">id</param>
        /// <param name="blogInf">返回日志的信息</param>
        /// <param name="comment">返回评论的相关信息</param>
        /// <returns>返回该用户日志的总数</returns>
        int GetAllInfo(int userId, int blogId, bool increaseReads, out BlogInfo blogInf, out List<BlogCommentInfo> comment);

        void UpdateBlogFoot(int BlogID, int UserID);

        #endregion
        #region 管理后台
        /// <summary>
        /// 日志搜索
        /// </summary>
        /// <param name="searchCondition">搜索条件:1.按作者姓名;2.按日志标题</param>
        /// <param name="keyword">搜索关键字</param>
        /// <param name="orderType">排序方式:1.按发表日期;2.按作者姓名;3.按评论数</param>
        /// <returns></returns>
        DataTable Search(int searchCondition, string keyword, int orderType, int pageIndex, int pageSize, out int recordCount, out int pageCount);
        /// <summary>
        /// 锁定或解锁日志
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="blogId"></param>
        /// <param name="lockSate"></param>
        int ChangeLock(int userId, int blogId, bool lockSate);
        #endregion
    }

    public sealed partial class DataAccess
    {
        public static IBlog CreateBlog()
        {
            string className = path + ".Blog";
            return (IBlog)Assembly.Load(path).CreateInstance(className);
        }
    }
}
