using MediaBrowser.Controller;
using MediaBrowser.Model.System;
using ServiceStack;
using System.Threading.Tasks;
namespace MediaBrowser.Api
{
    /// 
    /// Class GetSystemInfo
    /// 
    [Route("/System/Info", "GET")]
    [Api(Description = "Gets information about the server")]
    public class GetSystemInfo : IReturn
    {
    }
    /// 
    /// Class RestartApplication
    /// 
    [Route("/System/Restart", "POST")]
    [Api(("Restarts the application, if needed"))]
    public class RestartApplication
    {
    }
    [Route("/System/Shutdown", "POST")]
    [Api(("Shuts down the application"))]
    public class ShutdownApplication
    {
    }
    
    /// 
    /// Class SystemInfoService
    /// 
    public class SystemService : BaseApiService
    {
        /// 
        /// The _app host
        /// 
        private readonly IServerApplicationHost _appHost;
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// The app host.
        /// jsonSerializer
        public SystemService(IServerApplicationHost appHost)
        {
            _appHost = appHost;
        }
        /// 
        /// Gets the specified request.
        /// 
        /// The request.
        /// System.Object.
        public object Get(GetSystemInfo request)
        {
            var result = _appHost.GetSystemInfo();
            return ToOptimizedResult(result);
        }
        /// 
        /// Posts the specified request.
        /// 
        /// The request.
        public void Post(RestartApplication request)
        {
            Task.Run(async () =>
            {
                await Task.Delay(100).ConfigureAwait(false);
                await _appHost.Restart().ConfigureAwait(false);
            });
        }
        /// 
        /// Posts the specified request.
        /// 
        /// The request.
        public void Post(ShutdownApplication request)
        {
            Task.Run(async () =>
            {
                await Task.Delay(100).ConfigureAwait(false);
                await _appHost.Shutdown().ConfigureAwait(false);
            });
        }
    }
}