using ASHermed.SinoInterface.Api.ContractModel;
using ASHermed.SinoInterface.Api.ContractModel.App;
using ASHermed.SinoInterface.Api.ContractModel.Framework.Login;
using ASHermed.SinoInterface.Api.IRepository;
using ASHermed.SinoInterface.Api.IService;
using ASHermed.SinoInterface.Code;
using ASHermed.SinoInterface.ContractModel;
using ASHermed.SinoInterface.Exception;
using ASHermed.SinoInterface.IFramework;
using ASHermed.SinoInterface.IFramework.SingleSignOn;
using ASHermed.SinoInterface.Tools;
using JWT;
using JWT.Algorithms;
using JWT.Serializers;
using Newtonsoft.Json.Linq;
using PoJun.Util;
using PoJun.Util.Maps;
using Renci.SshNet.Security;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace ASHermed.SinoInterface.Api.Service
{
    /// <summary>
	/// 三方服务
	/// </summary>
	public class SanFangService : BaseService, ISanFangService
    {
        ISanFangRepository _sanFangRepository;
        IJpushService _jpushService;
        IOrderService _orderService;
        IPubUserInfoRepository _pubUserInfoRepository;
        /// <summary>
        /// 三方服务
        /// </summary>
        public SanFangService(ISanFangRepository sanFangRepository, IJpushService jpushService, IOrderService orderService, IPubUserInfoRepository pubUserInfoRepository)
        {
            _sanFangRepository = sanFangRepository;
            _jpushService = jpushService;
            _orderService = orderService;
            _pubUserInfoRepository = pubUserInfoRepository;
        }

        public int SaveQiMoMsg(QimoReq qimo)
        {
            Pub_Message_Qimo model = new Pub_Message_Qimo();
            model.Content = qimo.content;
            model.CreateTime = DateTime.Now;
            model.IsRead = false;
            model.UserId = Convert.ToInt32(qimo.userId);
            var res = _sanFangRepository.InsertPubMessageQimo(model);
            if (res > 0)
            {
                var user = _pubUserInfoRepository.SelectByPrimaryKey(model.UserId);
                if (user != null)
                {
                    _orderService.PushUserMessage(user, "35", "您收到了一条新的消息！", "客服小影：" + model.Content);
                }
            }
            return res;
        }

        public int ReadQimoMessage(int userId)
        {
            return _sanFangRepository.ReadQimoMessage(userId);
        }

        public int GetQimoMessage(int userId)
        {
            return _sanFangRepository.GetQimoMessage(userId);
        }

    }
}
