using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Mvc;
using AipGateway.Web.Models;
using System.Text.Json;

// https://stackoverflow.com/questions/49073658/how-to-return-json-in-an-apicontroller-for-a-single-method
namespace AipGateway.Web.Controllers
{
    public class UploadController : ApiController
    {
        // GET: v1/Upload
        // public IEnumerable<string> Get()
        // {
        //     return new string[] { "value1", "value2" };
        // }
        public IHttpActionResult Get()
        {
            var model = new ErrorResponse();
            return Ok(model);
            // return Json(model);
        }

        //public HttpResponseMessage Get([FromUri] GeoPoint location) { ... }

        // GET: v1/Upload/5
        //[System.Web.Mvc.Route("api/Player/videos")]
        //[Route("api/Player/videos")]
        // [OperationContract]
        // [WebGet(UriTemplate = "GetData/{value}", ResponseFormat = WebMessageFormat.Json)]
        public HttpResponseMessage Get(int id)
        {
            var error = new ErrorResponse();
            string result = JsonSerializer.Serialize<ErrorResponse>(error);
            var opt = new JsonSerializerOptions() { WriteIndented = true };
            string result1 = JsonSerializer.Serialize<ErrorResponse>(error, opt);

            var errorList = new List<ErrorResponse>();
            errorList.Add(new ErrorResponse());
            errorList.Add(new ErrorResponse());
            var opt1 = new JsonSerializerOptions(){ WriteIndented=true };
            string strJson = JsonSerializer.Serialize<IList<ErrorResponse>>(errorList, opt1);

            // Department dept = new Department() { DeptId = 101, DepartmentName = "IT" };
            // byte[] utf8bytesJson = JsonSerializer.SerializeToUtf8Bytes(dept);
            // string strJson = System.Text.Encoding.UTF8.GetString(utf8bytesJson);

            // var o = new UserResponse();
            // o.Age = "25";
            // o.Gender = "Male";
            // o.Message = "Hello";
            // o.UserInfo = new User();
            // o.UserInfo.Id = 1;
            // o.UserInfo.FirstName = "John";
            // o.UserInfo.LastName = "Doe";
            // o.UserInfo.Balance = 1000M;
            // var json = JsonConvert.SerializeObject(o, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });

            return Request.CreateResponse(HttpStatusCode.OK, error, Configuration.Formatters.JsonFormatter);
            // return Json(error, JsonRequestBehavior.AllowGet);
        }

        // POST: v1/Upload
        public IHttpActionResult Post([FromBody] UploadRequest req)
        {
            var error = new ErrorResponse();
            req.files = new List<string>();
            if (req.files == null || req.files.Count == 0)
            {
                req.files.Add("c:\\Data\\sample.pptx");
            }
            return Ok(req);
        }
    }

}
