using Furion;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TempTask.WebEntry.ApiController.Dto;
using TempTask.WebEntry.Tools;

namespace TempTask.WebEntry.ApiController
{
    /// <summary>
    /// 
    /// </summary>
    public class NumZjController : IDynamicApiController
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public async Task<dynamic> Download([FromBody] NumZjDownloadInput numZjDownloadInput)
        {
            //var asd = ExcelHelper.ToColumnIndex("C");
            //return null;
            return await Task.Run(() =>
            {
                var configs = App.GetConfig<NumZjConfig>("NumZjConfig");
                var current = configs.numZjExcels.Find(a => (int)a.excel_no == numZjDownloadInput.type);
                var filepath = NumZjHelper.WriteTemplate(numZjDownloadInput.year, numZjDownloadInput.month, numZjDownloadInput.week, current);
                return new FileStreamResult(new FileStream(filepath, FileMode.Open), "application/octet-stream") { FileDownloadName = current.excel_name };
            });
        }
    }
}
