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.GenericContent;
using Qusion.Cms.GenericContent.Core;
using Qusion.Cms.Web.Http;
using Qusion.WebApp.Areas.cms.Filters;
using Qusion.WebApp.Areas.cms.Models.GenericContents;
using Qusion.Cms.Site.Core;
using Qusion.Cms.Site;
using Qusion.Framework.Configuration;
using Qusion.WebApp.Areas.cms.Helpers;

namespace Qusion.WebApp.Areas.cms.Controllers
{
    public class GenericContentLaktasiController : ApiController
    {
        private readonly GenericContentService _genericContentService;
        private readonly PageService _pageService;
        public GenericContentLaktasiController(GenericContentService genericContentService, PageService pageService)
        {
            _genericContentService = genericContentService;
            _pageService = pageService;
        }

        [HttpGet]
      [Compress]
        public PageResult<ContentListModel> Query([FromUri] ContentQueryInput input)
        {
         
                GenericContentQuery query = Mapper.Map(input, GenericContentQuery.Default) ?? GenericContentQuery.Default;
                IEnumerable<GenericContent> contents = _genericContentService.Search(query);
                var a = contents.ToList().Where(x => x.Title != null);
                IList<ContentListModel> model = Mapper.Map<IList<GenericContent>, IList<ContentListModel>>(a.ToList());

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

        [HttpGet]
      [Compress]
        public ContentModel Get(Guid pageId)
        {
          
                GenericContent content = _genericContentService.GetByPageID(pageId);
                return Mapper.Map<GenericContent, ContentModel>(content);
        }
        

    }
}