using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.FileProviders;
using System.IO;

namespace IRaCIS.Core.API
{
    public static class IRacisHostFileStore
    {

        public static void UseIRacisHostStaticFileStore(this IApplicationBuilder app, IWebHostEnvironment _hostEnvironment)
        {

            var iRaCISDataFolder = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);

            if (!Directory.Exists(iRaCISDataFolder))
            {
                Directory.CreateDirectory(iRaCISDataFolder);
            }

            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(iRaCISDataFolder),
                RequestPath = $"/{StaticData.Folder.IRaCISDataFolder}",
                ServeUnknownFileTypes = true,
                DefaultContentType = "application/octet-stream"
            });
        }
    }
}
