using Hotline.CallCenter.BlackLists;
using Hotline.CallCenter.Calls;
using Hotline.CallCenter.Tels;
using Hotline.Share.Dtos;
using Hotline.Share.Dtos.CallCenter;
using Hotline.Share.Dtos.TrCallCenter;
using Hotline.Share.Enums.CallCenter;

namespace Hotline.Application.CallCenter
{
    public interface ICallApplication
    {
        /// <summary>
        /// 查询分机
        /// </summary>
        Task<(int, IList<TelDto>)> QueryTelsAsync(QueryTelsInDto dto, CancellationToken cancellationToken);

        /// <summary>
        /// 查询分机组
        /// </summary>
        Task<IReadOnlyList<TelGroupDto>> QueryTelGroupsAsync(CancellationToken cancellationToken);

        #region 黑名单

        /// <summary>
        /// 新增黑名单
        /// </summary>
        Task<string> AddBlackListAsync(AddBlacklistDto dto, CancellationToken cancellationToken);

        /// <summary>
        /// 删除黑名单
        /// </summary>
        Task RemoveBlackListAsync(string id, CancellationToken cancellationToken);

        /// <summary>
        /// 查询黑名单
        /// </summary>
        Task<List<Blacklist>> QueryBlackListsAsync(CancellationToken cancellationToken);

        #endregion

        /// <summary>
        /// 签入
        /// </summary>
        Task<TrOnDutyResponseDto> SignInAsync(SignInDto dto, CancellationToken cancellationToken);

        /// <summary>
        /// 签出
        /// </summary>
        Task SingOutAsync(CancellationToken cancellationToken);

        /// <summary>
        /// 签出
        /// </summary>
        Task SingOutAsync(string telNo, CancellationToken cancellationToken);

        /// <summary>
        /// 查询当前用户的分机状态
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<TrOnDutyResponseDto> GetTelStateAsync(CancellationToken cancellationToken);

        /// <summary>
        /// 定量查询通话记录
        /// </summary>
        Task<IReadOnlyList<CallNativeDto>> QueryCallsFixedAsync(QueryCallsFixedDto dto, CancellationToken cancellationToken);

        /// <summary>
        /// 查询分机操作记录（定量）
        /// </summary>
        Task<IReadOnlyList<TelOperation>> QueryTelOperationsAsync(QueryTelOperationsFixedDto dto,
            CancellationToken cancellationToken);

        /// <summary>
        /// 依据通话记录编号获取映射后的callId
        /// </summary>
        Task<string> GetOrSetCallIdAsync(string callNo, CancellationToken cancellationToken);

        Task<CallidRelation> GetRelationAsync(string callNo, CancellationToken cancellation);

        Task AddRelationAsync(CallidRelation relation, CancellationToken cancellation);

        /// <summary>
        /// 乐观并发更新映射关系
        /// </summary>
        Task<int> UpdateRelationOptLockAsync(CallidRelation relation, CancellationToken cancellationToken);

        /// <summary>
        /// 查询通话记录列表
        /// </summary>
        Task<List<CallNative>> GetCallListAsync(string callId, CancellationToken cancellationToken);

        /// <summary>
        /// 查询通话记录
        /// </summary>
        /// <param name="callId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<CallNative?> GetCallAsync(string callId, CancellationToken cancellationToken);

        /// <summary>
        /// 查询通话记录
        /// </summary>
        Task<List<CallNative>> QueryCallsAsync(
            string? phone = null,
            ECallDirection? direction = null,
            DateTime? callStartTimeStart = null,
            DateTime? callStartTimeEnd = null,
            CancellationToken cancellationToken = default);

        #region tianrun

        Task<TrCallRecord?> GetTianrunCallAsync(string callId, CancellationToken cancellationToken);

		/// <summary>
		///  根据转写ID获取通话信息
		/// </summary>
		/// <returns></returns>
		Task<TrCallRecord?> GetTianrunCallTransliterationAsync(string transliterationId, CancellationToken cancellationToken);
		/// <summary>
		/// 修改转写状态
		/// </summary>
		/// <returns></returns>
		Task EditTransliterationStateAsync(string callId, ECallTransliterationState state,string transliterationId, CancellationToken cancellationToken);

		/// <summary>
		/// 关联通话记录与order（添润）
		/// </summary>
		Task RelateTianrunCallWithOrderAsync(string callId, string orderId, CancellationToken cancellationToken);

        /// <summary>
        /// 查询通话记录
        /// </summary>
        Task<List<TrCallRecord>> QueryTianrunCallsAsync(
            string? phone = null,
            ECallDirection? direction = null,
            DateTime? callStartTimeStart = null,
            DateTime? callStartTimeEnd = null,
            CancellationToken cancellationToken = default);

        #endregion

        /// <summary>
        /// 查询分机操作选项
        /// </summary>
        /// <returns></returns>
        List<Kv> GetTelOperationOptions();
    }
}