using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dao;
using Domain;

namespace Service.Implement
{
    public class SysOauth2Manager : GenericManagerBase<SysOauth2>, ISysOauth2Manager
    {
        public IList<SysOauth2> LoadAllByPage(out long total, int page, int rows, string order, string sort)
        {
            return ((ISysOauth2Repository)(this.CurrentRepository)).LoadAllByPage(out total, page, rows, order, sort).ToList();
        }
        /// <summary>
        /// 根据code获取最新的授权记录，如果授权记录已过期，则返回null
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public SysOauth2 Get(string code)
        {
            var sysOauth2 = ((ISysOauth2Repository)(this.CurrentRepository)).Get(code);
            if (null != sysOauth2)
            {
                if (sysOauth2.CreatedDate.AddSeconds(sysOauth2.ExpiresIn) < DateTime.Now)
                {
                    return null;
                }
            }
            return sysOauth2;
        }

        public SysOauth2 GetByRefreshToken(string refreshToken)
        {
            return ((ISysOauth2Repository)(this.CurrentRepository)).GetByRefreshToken(refreshToken);
        }
        /// <summary>
        /// 获取小度token
        /// </summary>
        /// <returns></returns>
        public string GetXiaoDuToken()
        {
            return ((ISysOauth2Repository)(this.CurrentRepository)).GetXiaoDuToken();
        }
    }
}
