using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Alvas.Audio;
using System;
using System.IO;
using System.Linq;
// https://www.mikesdotnetting.com/article/318/working-with-json-in-razor-pages
namespace WebCs.Pages
{
    public class FormatsModel : PageModel
    {
        public FormatsModel()
        {
        }
        // [BindProperty]
        // public int ndx { get; set; }
        // public async Task<string> OnPostAsync()
//         public void OnPost()//JsonResult//string id
// {
//     // var contents = await 
//     // return "alvas";
//     Console.WriteLine("id");
//             // return new JsonResult(id);
// }
        public JsonResult OnGetConvert(string id) {
            return new JsonResult(id);
        }
        public JsonResult OnGet(string id)
        {
            var fileName = Path.Combine(@"wwwroot\Audio", id);//"rec2.wav"
            IAudioReader wr = new WaveReader(System.IO.File.OpenRead(fileName));
            var format = wr.ReadFormat();
            var data = wr.ReadData();
            Console.WriteLine($"data: {data.Length}");
        FormatDetails[] fdArr = AudioCompressionManager.GetCompatibleFormatList(format);
        for (int i = 0; i < fdArr.Length; i++)
        {
            fdArr[i].ShowFormatTag = true;
            Console.WriteLine(fdArr[i]);
        }
            return new JsonResult(fdArr.Select(fd => fd.ToString()));
        }
    }
}