using System;
using System.IO;
using System.Web.Mvc;
using Kreta.Core;

namespace Kreta.Web.Controllers
{
    [AllowAnonymous]
    public class CacheController : Controller
    {
        /// <summary>
        /// Wraps the stored MemoryStream into an Excel file.
        /// </summary>
        /// <param name="guid">Unique identifier of the file.</param>
        /// <param name="fileName">File download name.</param>
        /// <param name="contentType">Content type of the returned FileStream.</param>
        /// <returns>The requested file as a FileStreamResult.</returns>
        [HttpGet]
        public ActionResult DownloadFile(Guid guid, string fileName, string contentType)
        {
            var stream = Cache.Get(guid) as MemoryStream;

            return new FileStreamResult(stream, contentType) { FileDownloadName = fileName };
        }
    }
}