using System;
using System.Web.Mvc;
using Kreta.BusinessLogic.Helpers;
using Kreta.BusinessLogic.Security;
using Kreta.Web.Areas.Intezmeny.ApiControllers;
using Kreta.Web.Areas.Intezmeny.Models;
using Kreta.Web.Helpers;
using Kreta.Web.Security;

namespace Kreta.Web.Areas.Intezmeny.Controllers
{
    [MvcRoleClaimsAuthorize(true)]
    [MvcRolePackageDenyAuthorize(KretaClaimPackages.IsOnlyAlkalmozott.ClaimValue)]
    [MvcRolePackageAuthorize(KretaClaimPackages.Ellenorzo.ClaimValue)]
    public class FaliujsagController : Controller
    {
        public ActionResult Index()
        {
            var model = new FaliujsagModel
            {
                LegutobbiMulasztasok = new MulasztasHelper(ConnectionTypeExtensions.GetActiveSessionConnectionType()).GetTanuloLegutobbiMulasztasai(ClaimData.FelhasznaloId),
                LegutobbiFeljegyzesek = new FeljegyzesekHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetLegutobbiFeljegyzesek(),
                LegutobbiBejelentettSzamonkeresek = new SzamonkeresElorejelzesHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetLegutobbiBejelentettSzamonkeresek(ClaimData.FelhasznaloId),
                LegutobbiErtekelesek = new TanuloErtekelesHelper(ConnectionTypeExtensions.GetSessionConnectionType()).
                                        GetTanuloLegfrissebbTanuloErtekelesList(ClaimData.FelhasznaloId)
            };

            return View(model);
        }

        public JsonResult GetMoreEntries(int startindex, int range)
        {
            FaliujsagModel model = new FaliujsagApiController().GetFaliujsagBejegyzesek(DateTime.Now, startindex, range);
            model.ItemCount = model.FaliujsagElemek.Count;

            var result = new JsonResult()
            {
                Data = model,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            return result;
        }
    }
}