using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using AutoMapper;
using Qusion.Cms.Classifications;
using Qusion.Cms.Classifications.Core;
using Qusion.Cms.Core.Domain;
using Qusion.Cms.Core.Exceptions;
using Qusion.Cms.Modules.Events;
using Qusion.Cms.Modules.Events.Core;
using Qusion.Cms.Users.Core;
using Qusion.Cms.Users.Domain;
using Qusion.Cms.Web.Http;
using Qusion.WebApp.Areas.cms.Filters;
using Qusion.WebApp.Areas.cms.Models.Events;
using Qusion.Framework.Configuration;
using Qusion.WebApp.Areas.cms.Helpers;

namespace Qusion.WebApp.Areas.cms.Controllers
{
    //[Authorize]
    public class EventLaktasiController : ApiController
    {
        private readonly EventService _eventService;
        private readonly LabelService _labelService;
  

        public EventLaktasiController(EventService eventService, LabelService labelService)
        { 
            _eventService = eventService;
            _labelService = labelService;
        }

        [HttpGet]
        [Compress]
        public PageResult<EventListModel> Query([FromUri] EventQueryInput input)
        {
          
                EventQuery query = Mapper.Map(input, EventQuery.Default) ?? EventQuery.Default;
                IEnumerable<Event> events = _eventService.Search(query);
                var a = events.ToList().Where(x => x.Title != null).Where(x => x.EndsOn >= DateTime.Now);
                IList<EventListModel> model = Mapper.Map<IList<Event>, IList<EventListModel>>(a.ToList());

                return new PageResult<EventListModel>
                {
                    Items = model,
                    Count = query.Paging.TotalCount
                };
            
        }

        [HttpGet]
      [Compress]
        public EventModel Get(Guid id)
        {
           Event _event = _eventService.GetById(id);
           return Mapper.Map<Event, EventModel>(_event);
        }
        
    }
}