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

namespace JuSNS.Home
{
    public class Blog
    {
        private IBlog dal;
        /// <summary>
        /// 构造函数
        /// </summary>
        public Blog()
        {
            dal = DataAccess.CreateBlog();
        }
        /// <summary>
        /// 取得某条日志或草稿
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="isdraft"></param>
        /// <returns></returns>
        public BlogInfo GetBlog(int blogid, bool isdraft)
        {
            return dal.GetBlog(blogid, isdraft);
        }
        /// <summary>
        /// 发表新日志或草稿
        /// </summary>
        /// <param name="info"></param>
        /// <param name="isdraft">是不是草稿</param>
        /// <returns>如果成功则返回添加的日志ID</returns>
        public int Deliver(BlogInfo info, bool isdraft)
        {
            return dal.Deliver(info, isdraft);
        }
        /// <summary>
        /// 修改日志或草稿
        /// </summary>
        /// <param name="info"></param>
        /// <param name="draftSate">0保存日志，1保存草稿，2本来是草稿-保存为日志</param>
        /// <returns></returns>
        public int Edit(BlogInfo info, int draftSate)
        {
            return dal.Edit(info, draftSate);
        }
        /// <summary>
        /// 对日志发表评论
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="userid"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public int CommentsBlog(int blogid, int userid, string content)
        {
            return dal.CommentsBlog(blogid, userid, content);
        }
        /// <summary>
        /// 删除日志评论,只有评论者或日志发表者可删除
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="commentid"></param>
        /// <returns></returns>
        public int DelComment(int userid, int commentid)
        {
            return dal.DelComment(userid, commentid);
        }
        /// <summary>
        /// 删除日志
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="blogid"></param>
        /// <returns></returns>
        public int DelBlog(int userid, int blogid)
        {
            return dal.DelBlog(userid, blogid, false);
        }
        /// <summary>
        /// 发表草稿
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="draftid"></param>
        /// <returns></returns>
        public int DeliverDraft(int userid, int draftid)
        {
            return dal.DeliverDraft(userid, draftid);
        }
        /// <summary>
        /// 删除草稿
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="draftid"></param>
        /// <returns></returns>
        public int DelDraft(int userid, int draftid)
        {
            return dal.DelDraft(userid, draftid);
        }
        /// <summary>
        /// 返回日志的所有信息
        /// </summary>
        /// <param name="userId">登录用户ID</param>
        /// <param name="blogId">id</param>
        /// <param name="blogInf">返回日志的信息</param>
        /// <param name="comment">返回评论的相关信息</param>
        /// <returns>返回该用户日志的总数</returns>
        public int GetAllInfo(int userId, int blogId, bool increaseReads, out BlogInfo blogInf, out List<BlogCommentInfo> comment)
        {
            return dal.GetAllInfo(userId, blogId, increaseReads, out blogInf, out comment);
        }

        /// <summary>
        /// 更新足迹！
        /// </summary>
        /// <param name="BlogID"></param>
        /// <param name="UserID"></param>
        public void UpdateBlogFoot(int BlogID, int UserID)
        {
            dal.UpdateBlogFoot(BlogID, UserID);
        }

    }
}
