using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Cors;

using AutoMapper;

using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.DataContract;


namespace skydiveLogs_api.Controllers
{
    public class StatsController : Base
    {
        public StatsController(IStatsService statsService,
                               IMapper mapper)
        {
            _statsService = statsService;
            _mapper = mapper;
        }

        [HttpGet("Simple")]
        [EnableCors]
        public SimpleSummaryResp Simple()
        {
            var result = _statsService.GetSimpleSummary(ConnectedUser);

            return _mapper.Map<SimpleSummaryResp>(result);
        }

        [HttpGet("ByDz")]
        [EnableCors]
        public IEnumerable<StatisticResp> ByDz()
        {
            var result = _statsService.GetStatsByDz(ConnectedUser);

            return _mapper.Map<IEnumerable<StatisticResp>>(result);
        }

        [HttpGet("ByAircraft")]
        [EnableCors]
        public IEnumerable<StatisticResp> ByAircraft()
        {
            var result = _statsService.GetStatsByAircraft(ConnectedUser);

            return _mapper.Map<IEnumerable<StatisticResp>>(result);
        }

        [HttpGet("ByJumpType")]
        [EnableCors]
        public IEnumerable<StatisticResp> ByJumpType()
        {
            var result = _statsService.GetStatsByJumpType(ConnectedUser);

            return _mapper.Map<IEnumerable<StatisticResp>>(result);
        }

        [HttpGet("ByGear")]
        [EnableCors]
        public IEnumerable<StatisticResp> ByGear()
        {
            var result = _statsService.GetStatsByGear(ConnectedUser);

            return _mapper.Map<IEnumerable<StatisticResp>>(result);
        }

        [HttpGet("ByYear")]
        [EnableCors]
        public IEnumerable<StatisticResp> ByYear()
        {
            var result = _statsService.GetStatsByYear(ConnectedUser);

            return _mapper.Map<IEnumerable<StatisticResp>>(result);
        }

        [HttpGet("ForLastYear")]
        [EnableCors]
        public StatisticForLastYearResp ForLastYear()
        {
            var resultByDz = _statsService.GetStatsForLastYearByDz(ConnectedUser);
            var resultByJumpType = _statsService.GetStatsForLastYearByJumpType(ConnectedUser);

            var result = new StatisticForLastYearResp();
            result.ByDz = _mapper.Map<IEnumerable<StatisticResp>>(resultByDz);
            result.ByJumpType = _mapper.Map<IEnumerable<StatisticResp>>(resultByJumpType);

            return result;
        }

        [HttpGet("ForLastMonth")]
        [EnableCors]
        public StatisticForLastMonthResp ForLastMonth()
        {
            var resultByDz = _statsService.GetStatsForLastMonthByDz(ConnectedUser);
            var resultByJumpType = _statsService.GetStatsForLastMonthByJumpType(ConnectedUser);

            var result = new StatisticForLastMonthResp();
            result.ByDz = _mapper.Map<IEnumerable<StatisticResp>>(resultByDz);
            result.ByJumpType = _mapper.Map<IEnumerable<StatisticResp>>(resultByJumpType);

            return result;
        }

        #region Private properties
        private readonly IStatsService _statsService;

        private readonly IMapper _mapper;
        #endregion
    }
}
