using Hotline.Api.Filter;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using System.IO;
using Microsoft.AspNetCore.Authorization;

namespace Hotline.Api.Controllers;

[ApiController]
[Produces("application/json")]
[Route("api/v1/[controller]")]
[Authorize(Policy = AppDefaults.AuthPolicy.Hotline)]
public class BaseController : ControllerBase
{
    protected FileStreamResult ExcelStreamResult(Stream stream, string fileName = null)
    {
        var tail = DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx";
        fileName = string.IsNullOrEmpty(fileName)
            ? tail
            : $"{fileName}_{tail}";
        HttpContext.Response.Headers.TryAdd("Access-Control-Expose-Headers", "Content-Disposition");
        return new FileStreamResult(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
        {
            FileDownloadName = fileName
        };
    }
}

[ApiController]
[Route("api/v1/[controller]")]
public class OriginController : ControllerBase
{

}