using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TreeListViewTester.Models;
using Newtonsoft.Json;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

namespace TreeListViewTester.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        public IActionResult LoadBaseView()
        {
            return View();
        }

        public JsonResult GetDataForTS([DataSourceRequest] DataSourceRequest request)
        {
            var data = new List<StudentHeirarchy>
            {
                new StudentHeirarchy {StudentID = 1, StudentName = "Tommy Smith", InstructorName = "Mr. Anderson", InstructorID = null  },
                new StudentHeirarchy {StudentID = 2, StudentName = "Made Up Name", InstructorName = "Mr. Anderson", InstructorID = 1  },
                new StudentHeirarchy {StudentID = 3, StudentName = "R.L. Stine", InstructorName = "Mr. Anderson", InstructorID = 2  },
                new StudentHeirarchy {StudentID = 4, StudentName = "AK1200", InstructorName = "Mrs. Smith", InstructorID = 1  },
                new StudentHeirarchy {StudentID = 5, StudentName = "Photek", InstructorName = "Mrs. Smith", InstructorID = 3  },
                new StudentHeirarchy {StudentID = 6, StudentName = "Steve Aoki", InstructorName = "Mrs. Smith", InstructorID = 1  }
            };

                return Json(data.ToTreeDataSourceResult(request,
                e => e.InstructorID,
                e => e.StudentID,
                e => e));
        }

        private string StudentTeacherData()
        {
            var data = new List<StudentHeirarchy>
            {
                new StudentHeirarchy {StudentID = 1, StudentName = "Tommy Smith", InstructorName = "Mr. Anderson", InstructorID = null  },
                new StudentHeirarchy {StudentID = 2, StudentName = "Made Up Name", InstructorName = "Mr. Anderson", InstructorID = 1  },
                new StudentHeirarchy {StudentID = 3, StudentName = "R.L. Stine", InstructorName = "Mr. Anderson", InstructorID = 1  },
                new StudentHeirarchy {StudentID = 4, StudentName = "AK1200", InstructorName = "Mrs. Smith", InstructorID = 2  },
                new StudentHeirarchy {StudentID = 5, StudentName = "Photek", InstructorName = "Mrs. Smith", InstructorID = 2  },
                new StudentHeirarchy {StudentID = 6, StudentName = "Steve Aoki", InstructorName = "Mrs. Smith", InstructorID = 3  }
            };

            return JsonConvert.SerializeObject(data);
        }
    }
}
