using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Net;
using ServiceStack.Web;
using System.IO;
namespace MediaBrowser.Server.Implementations.HttpServer
{
    public class SwaggerService : IHasResultFactory, IRestfulService
    {
        private readonly IApplicationPaths _appPaths;
        public SwaggerService(IApplicationPaths appPaths)
        {
            _appPaths = appPaths;
        }
        /// 
        /// Gets the specified request.
        /// 
        /// The request.
        /// System.Object.
        public object Get(GetSwaggerResource request)
        {
            var runningDirectory = Path.GetDirectoryName(_appPaths.ApplicationPath);
            var swaggerDirectory = Path.Combine(runningDirectory, "swagger-ui");
            var requestedFile = Path.Combine(swaggerDirectory, request.ResourceName.Replace('/', Path.DirectorySeparatorChar));
            return ResultFactory.GetStaticFileResult(Request, requestedFile);
        }
        /// 
        /// Gets or sets the result factory.
        /// 
        /// The result factory.
        public IHttpResultFactory ResultFactory { get; set; }
        /// 
        /// Gets or sets the request context.
        /// 
        /// The request context.
        public IRequest Request { get; set; }
    }
}