using AutoMapper;
using DataAccess;
using DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLayer
{
    public class ReportManager : BLBase
    {

        public IList<ExecutiveReportDTO> GetExecutiveReport(DateTime Date, int Executive_Id)
        {
            IList<GetExecutiveReport_Result> Result = context.GetExecutiveReport(Date.Month, Date.Year, Executive_Id).ToList();

            IList<ExecutiveReportDTO> ExecutiveReport = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetExecutiveReport_Result, ExecutiveReportDTO>();
                ExecutiveReport = Mapper.Map<IList<GetExecutiveReport_Result>, IList<ExecutiveReportDTO>>(Result);
            }

            return ExecutiveReport;
        }


        public ExecutiveTargetsActualsDTO GetExecutiveTargetsActuals(DateTime Date, int Executive_Id)
        {
            GetExecutiveTargetsActuals_Result Result = context.GetExecutiveTargetsActuals(Date.Month, Date.Year, Executive_Id).FirstOrDefault();

            ExecutiveTargetsActualsDTO ExecutiveTargetsActuals = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetExecutiveTargetsActuals_Result, ExecutiveTargetsActualsDTO>();
                ExecutiveTargetsActuals = Mapper.Map<GetExecutiveTargetsActuals_Result, ExecutiveTargetsActualsDTO>(Result);
            }

            return ExecutiveTargetsActuals;
        }

        public IList<ManagerReportDTO> GetManagerReport(DateTime? FromDate, DateTime? ToDate, int? CountryId, int? RegionId, int? LocationId,
                                                        string KeyAccounts, int ManagerId, int? SearchExecutiveId, bool ReportExecutiveWise)
        {
            bool? KeyAct = null;
            if (KeyAccounts == "2")
                KeyAct = true;
            if (KeyAccounts == "3")
                KeyAct = false;

            IList<GetManagerReport_Result> Result = context.GetManagerReport(FromDate, ToDate, (CountryId == 0) ? null : CountryId,
                                                    (RegionId == 0) ? null : RegionId, (LocationId == 0) ? null : LocationId, KeyAct, 
                                                    ManagerId, SearchExecutiveId, ReportExecutiveWise).ToList();

            IList<ManagerReportDTO> ManagerReportList = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetManagerReport_Result, ManagerReportDTO>();
                ManagerReportList = Mapper.Map<IList<GetManagerReport_Result>, IList<ManagerReportDTO>>(Result);
            }

            return ManagerReportList;
        }
    }
}
