using System;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.ScheduledTasks.Triggers
{
    /// 
    /// Class StartupTaskTrigger.
    /// 
    public sealed class StartupTrigger : ITaskTrigger
    {
        private const int DelayMs = 3000;
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// The options of this task.
        public StartupTrigger(TaskOptions taskOptions)
        {
            TaskOptions = taskOptions;
        }
        /// 
        public event EventHandler? Triggered;
        /// 
        public TaskOptions TaskOptions { get; }
        /// 
        public async void Start(TaskResult? lastResult, ILogger logger, string taskName, bool isApplicationStartup)
        {
            if (isApplicationStartup)
            {
                await Task.Delay(DelayMs).ConfigureAwait(false);
                OnTriggered();
            }
        }
        /// 
        public void Stop()
        {
        }
        /// 
        /// Called when [triggered].
        /// 
        private void OnTriggered()
        {
            Triggered?.Invoke(this, EventArgs.Empty);
        }
    }
}