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.ContractModel;
using ASHermed.SinoInterface.IFramework.SingleSignOn;
using PoJun.Util.Maps;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace ASHermed.SinoInterface.Api.Service
{
    /// <summary>
	/// 微信用户信息
	/// </summary>
	public class PubUserInfoService : BaseService, IPubUserInfoService
    {
        #region 初始化
        IPubUserInfoRepository pubUserInfoRepository;
        IPubPatInfoRepository _pubPatInfoRepository;
        IPubMapUserPatRepository _pubMapUserPatRepository;
        public PubUserInfoService(IPubUserInfoRepository _pubUserInfoRepository, IPubPatInfoRepository pubPatInfoRepository, IPubMapUserPatRepository pubMapUserPatRepository)
        {
            pubUserInfoRepository = _pubUserInfoRepository;
            _pubPatInfoRepository = pubPatInfoRepository;
            _pubMapUserPatRepository = pubMapUserPatRepository;
        }
        #endregion

        public Pub_User_Info SelectByIdentifier(string identifier)
        {
            return pubUserInfoRepository.SelectByIdentifier(identifier);
        }

        public Pub_User_Info SelectByPhone(string acc)
        {
            return pubUserInfoRepository.SelectByPhone(acc);
        }

        public Pub_User_Info SelectByLinKinOpenId(string linKingOpenId)
        {
            return pubUserInfoRepository.SelectByLinKinOpenId(linKingOpenId);
        }

        public Pub_User_Info SelectByEmail(string acc)
        {
            return pubUserInfoRepository.SelectByEmail(acc);
        }

        public Pub_Map_User_Type SelectUserTypeByPhone(string phone)
        {
            return pubUserInfoRepository.SelectUserTypeByPhone(phone);
        }
        public Pub_User_Info SelectByAppOpenId(string openId)
        {
            return pubUserInfoRepository.SelectByAppOpenId(openId);
        }

        public Pub_User_Info SelectByAppOpenIdWithPhone(string openId, string account)
        {
            return pubUserInfoRepository.SelectByAppOpenIdWithPhone(openId, account);
        }

        public int UserComformInformed()
        {
            return pubUserInfoRepository.UserComformInformed(GetBaseUserInfo().ID);
        }

        public int PatInsuranceComform(string uId, bool isAgree)
        {
            var userId = GetBaseUserInfo().ID;
            var reletion = pubUserInfoRepository.SelectByPrimaryKey(userId);
            if (reletion == null || reletion.U_Id != uId)
            {
                return 0;
            }
            return _pubPatInfoRepository.PatInsuranceComform(uId, isAgree);
        }

        public Pub_Pat_Info SelectById(int id)
        {
            return _pubPatInfoRepository.SelectById(id);
        }

        public PatWithRelationShip SelectPatById(int id)
        {
            return _pubPatInfoRepository.SelectPatById(id);
        }


        public Pub_Pat_Info SelectByLinKingOpenId(string openid)
        {
            return _pubPatInfoRepository.SelectByLinKingOpenId(openid);
        }

        public int UpdatePatByLinKing(string linkingopenid, int patid)
        {
            return _pubPatInfoRepository.UpdatePatByLinKing(linkingopenid, patid);
        }
    }
}
