using Hotline.Share.Dtos.BatchTask;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotline.BatchTask
{
    public interface IApptaskDomainService
    {
        /// <summary>
        /// 新增任务
        /// </summary>
        Task<string> AddAsync(AddApptaskRequest request, CancellationToken cancellation);

        /// <summary>
        /// 查询任务进度
        /// </summary>
        /// <returns></returns>
        Task<ApptaskProgressDto> GetProgressAsync(string taskId, CancellationToken cancellation);
        
        /// <summary>
        /// 查询当前任务是否全部完成
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        Task<bool> IsCompletedAsync(string taskId, CancellationToken cancellation);

        /// <summary>
        /// 终止任务
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        Task TerminalTaskAsync(string taskId, CancellationToken cancellation);

        /*job request*/
        /// <summary>
        /// 获取一个待执行的任务
        /// </summary>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        Task<ApptaskItem?> GetWaitingTaskAsync(CancellationToken cancellation);

        /// <summary>
        /// 执行任务
        /// </summary>
        /// <param name="executor"></param>
        /// <param name="apptaskItem"></param>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        Task<ApptaskExecuteResult> ExecuteAsync<TRequest>(IApptaskExecutor<TRequest> executor, ApptaskItem apptaskItem, CancellationToken cancellation)
            where TRequest : class, IApptaskRequest;
    }
}
