namespace Hotline.BatchTask;

public interface IApptaskExecutor<TRequest>
{
    /// <summary>
    /// 执行任务
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellation"></param>
    /// <returns>是否成功执行</returns>
    Task<ApptaskExecuteResult> ExecuteAsync(TRequest? request, CancellationToken cancellation);
}


public class ApptaskExecuteResult
{
    public bool IsSuccess { get; set; }
    public string? Message { get; set; }

    public ApptaskExecuteResult()
    {

    }

    public ApptaskExecuteResult(bool isSuccess, string? message = null)
    {
        IsSuccess = isSuccess;
        Message = message;
    }

    public static ApptaskExecuteResult Success(string? message = null) => new(true, message ?? "成功");

    public static ApptaskExecuteResult Fail(string message) => new(false, message);
}