using Hotline.Caching.Interfaces;
using Hotline.CallCenter.Calls;
using XF.Domain.Cache;
using XF.Domain.Dependency;

namespace Hotline.Caching.Services
{
    public class CallCacheManager : ICallCacheManager, IScopeDependency
    {
        private readonly ITypedCache<CallDtoRedis> _cacheCall;

        public class CallDtoRedis
        {
            public string FromNo { get; set; }
            public string ToNo { get; set; }
            public DateTime InGroupTime { get; set; }
        }


        public CallCacheManager(ITypedCache<CallDtoRedis> cacheCall)
        {
            _cacheCall = cacheCall;
        }

        /// <summary>
        /// 新增或修改队列
        /// </summary>
        /// <param name="list"></param>
        public void AddCallCache(Call call)
        {
            _cacheCall.Set(call.Id, new CallDtoRedis { FromNo = call.FromNo, ToNo = call.ToNo, InGroupTime = DateTime.Now },TimeSpan.FromSeconds(90)); ;
        }

        /// <summary>
        /// 获取队列
        /// </summary>
        /// <returns></returns>
        public List<CallDtoRedis> GetCallQueueList()
        {
            var list = _cacheCall.GetListByPrefix().ToList();
            return list == null ? new List<CallDtoRedis>() : list;
        }


        /// <summary>
        /// 删除队列
        /// </summary>
        /// <param name="id"></param>
        public void RemoveCallCache(string id)
        {
            _cacheCall.Remove(id);
        }
    }
}
