﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using SPS.Model;
using SPS.Core;
using System.IO;
using System.ServiceModel.Web;
using System.Runtime.Serialization;
using SPS.BusinessLayer;

namespace SPS.Web
{
    [ServiceContract(Namespace = "http://cs.com")]
    public interface IPSPService
    {
        #region Authenciation
        [OperationContract]
        VFUserInfo Login(string name, string password);

        /// <summary>
        /// Signs the out.
        /// </summary>
        [OperationContract]
        void SignOut();

        /// <summary>
        /// Logins the status.
        /// </summary>
        /// <returns>
        /// The VF user info
        /// </returns>
        [OperationContract]
        VFUserInfo LoginStatus();
        #endregion

        #region Document operation
        [OperationAuthenticationBehavior(Role = VFUserBusinessLayer.RoleAdminDeveloper)]
        [OperationContract]
        DocumentInfo AddDocument(DocumentInfo document);

        [OperationAuthenticationBehavior(Role = VFUserBusinessLayer.RoleAdminDeveloper)]
        [OperationContract]
        DocumentInfo EditDocument(DocumentInfo document);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        DocumentInfo GetDocument(int documentID);

        [OperationAuthenticationBehavior(Role = VFUserBusinessLayer.RoleAdminDeveloper)]
        [OperationContract]
        bool DeleteDocument(int documentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        DocumentListInfo GetDocumentList(int parentDocumentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        DocumentListInfo GetDocumentListByPath(string parentDocumentPath);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        Uri PublishPage(int documentID);
        #endregion

        #region Content operation
        [OperationAuthenticationBehavior()]
        [OperationContract]
        ContentInfo AddContent(ContentInfo content);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        ContentInfo EditContent(ContentInfo content);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        bool DeleteContent(int contentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        ContentInfo GetContent(int contentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        ContentInfo CopyContentToPage(int contentID, int documentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        ContentInfo PublishContent(int contentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        ContentListInfo GetContentList(int parentDocumentID, int pageIndex, int pageSize, string contentTitle = null);

        [OperationContract]
        [OperationAuthenticationBehavior()]
        bool MoveContent(int contentID, int sequenceID);

        #endregion

        #region Import & Export
        [OperationContract]
        [OperationAuthenticationBehavior()]
        Stream ExportContentsFromPage(string documentID);

        [OperationContract]
        [OperationAuthenticationBehavior()]
        ContentInfo ImportContentToPage(ContentInfo content, bool overwrite, bool publish);

        #endregion

        #region image operation
        [OperationAuthenticationBehavior()]
        [OperationContract]
        RemoteFileInfo UploadImage(ClientFileInfo file);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        Uri UploadImageWithUrl(string documentPath, Uri imageUrl);
        #endregion

        [OperationAuthenticationBehavior()]
        [OperationContract]
        string GetContentFormTemplate(int documentID);
    }

    [ServiceContract(Namespace = "http://cs.com")]
    public interface IXMLPSPService
    {
        #region Output
        [OperationContract(Name = "XmlGetPageOutput")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
           BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetPageOutput/?id={documentID}")]
        Stream GetPageOutput(string documentID);

        [OperationContract(Name = "XmlGetPageOutputByPath")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
             BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetPageOutputByPath/?path={documentPath}")]
        Stream GetPageOutputByPath(string documentPath);

        [OperationContract(Name = "XmlGetContentOutput")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetContentOutput/?id={contentID}")]
        Stream GetContentOutput(string contentID);

        [OperationContract(Name = "XmlGetContentOutputByPath")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetContentOutputByPath/?path={contentPath}")]
        Stream GetContentOutputByPath(string contentPath);

        [OperationContract(Name = "XmlGetOutputByPath")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetOutputByPath/?path={path}")]
        Stream GetOutputByPath(string path);
        #endregion

        #region Authenciation
        [OperationContract(Name = "XmlLogin")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Login/{name}/{password}")]
        VFUserInfo Login(string name, string password);

        /// <summary>
        /// this is logout proxy.
        /// </summary>
        [OperationContract(Name = "XmlSignOut")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "SignOut/")]
        void SignOut();

        [OperationContract(Name = "XmlLoginStatus")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "LoginStatus/")]
        VFUserInfo LoginStatus();
        #endregion

        #region Content

        [OperationAuthenticationBehavior()]
        [OperationContract(Name="XmlGetContentFormTemplate")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetContentFormTemplate/?id={documentID}")]
        Stream GetContentFormTemplate(string documentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetContentXSLT/?id={documentID}")]
        Stream GetContentXSLT(string documentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetContentPageXSLT/?id={documentID}")]
        Stream GetContentPageXSLT(string documentID);

        [OperationAuthenticationBehavior()]
        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetSearchXSLT/?id={documentID}")]
        Stream GetSearchXSLT(string documentID);

        [OperationContract(Name = "XmlExportContentsFromPage")]
        [OperationAuthenticationBehavior()]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "ExportContentsFromPage/?id={documentID}")]
        Stream ExportContentsFromPage(string documentID);


        [OperationContract(Name = "ResetContentSequence")]
        [OperationAuthenticationBehavior()]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "ResetContentSequence/?id={documentID}")]
        bool ResetContentSequence(string documentID);

        #endregion

        #region Vote
        [OperationContract(Name = "XmlVote")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Vote/?id={contentID}&voteCount={voteCount}")]
        int Vote(int contentID, int voteCount = 1);

        [OperationContract(Name = "XmlRating")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Rating/?id={contentID}&rating={rating}")]
        double Rating(int contentID, int rating);

        [OperationContract(Name = "XmlSearch")]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Search/?publisher={publisher}&keyword={keyword}")]
        Stream Search(string publisher, string keyword);
        #endregion
    }

}