using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Model.Weather;
using ServiceStack.ServiceHost;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading;
namespace MediaBrowser.Api
{
    /// 
    /// Class Weather
    /// 
    [Route("/Weather", "GET")]
    public class GetWeather : IReturn
    {
        /// 
        /// Gets or sets the location.
        /// 
        /// The location.
        public string Location { get; set; }
    }
    /// 
    /// Class WeatherService
    /// 
    [Export(typeof(IRestfulService))]
    public class WeatherService : BaseRestService
    {
        /// 
        /// Gets the specified request.
        /// 
        /// The request.
        /// System.Object.
        public object Get(GetWeather request)
        {
            var kernel = (Kernel) Kernel;
            var location = string.IsNullOrWhiteSpace(request.Location) ? kernel.Configuration.WeatherLocation : request.Location;
            var result = kernel.WeatherProviders.First().GetWeatherInfoAsync(location, CancellationToken.None).Result;
            return ToOptimizedResult(result);
        }
    }
}