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

namespace BusinessLayer
{
    public class CommonManager : BLBase
    {
        public IList<AttendanceAndDSRDTO> GetAttandanceAndDSR(int? DatePreiod, DateTime? SpecificDate, int User_Id, int? Search_User_Id)
        {
            IList<GetAttendanceAndDSR_Result> Result = context.GetAttendanceAndDSR(DatePreiod, SpecificDate, User_Id, Search_User_Id).ToList();

            IList<AttendanceAndDSRDTO> AttendanceAndDSR = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetAttendanceAndDSR_Result, AttendanceAndDSRDTO>();
                AttendanceAndDSR = Mapper.Map<IList<GetAttendanceAndDSR_Result>, IList<AttendanceAndDSRDTO>>(Result);
            }

            return AttendanceAndDSR;
        }

        public IList<ManagerExecutivesDTO> GetLinkedExecutives(int Manager_Id)
        {
            IList<GetManagerExecutive_Result> Result = context.GetManagerExecutive(Manager_Id, null).ToList();

            IList<ManagerExecutivesDTO> LinkedExecutives = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetManagerExecutive_Result, ManagerExecutivesDTO>();
                Mapper.CreateMap<GetManagerExecutive_Result, ManagerExecutivesDTO>().ForMember(dest => dest.Site_User_Id,opt => opt.MapFrom(src => src.Executive_Id));
                Mapper.CreateMap<GetManagerExecutive_Result, ManagerExecutivesDTO>().ForMember(dest => dest.Site_User_Name, opt => opt.MapFrom(src => src.Name));
                LinkedExecutives = Mapper.Map<IList<GetManagerExecutive_Result>, IList<ManagerExecutivesDTO>>(Result);
            }

            return LinkedExecutives;
        }

        public IList<ParameterDTO> GetShiftNames()
        {
            IList<GetParameter_Result> Result = context.GetParameter(4, 0, 0).ToList();

            IList<ParameterDTO> ShiftNames = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetParameter_Result, ParameterDTO>();
                ShiftNames = Mapper.Map<IList<GetParameter_Result>, IList<ParameterDTO>>(Result);
            }

            return ShiftNames;
        }

        public IList<ParameterDTO> GetVisitObjective()
        {
            IList<GetParameter_Result> Result = context.GetParameter(8, 0, 0).ToList();

            IList<ParameterDTO> VisitObjective = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetParameter_Result, ParameterDTO>();
                VisitObjective = Mapper.Map<IList<GetParameter_Result>, IList<ParameterDTO>>(Result);
            }

            return VisitObjective;
        }

        public IList<LocationDTO> GetLocation(int? LocationId, string LocationName, int? RegionId)
        {
            IList<GetLocation_Result> Result = context.GetLocation(LocationId, string.IsNullOrEmpty(LocationName) ? null : LocationName, RegionId).ToList();

            IList<LocationDTO> Location = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetLocation_Result, LocationDTO>();
                Location = Mapper.Map<IList<GetLocation_Result>, IList<LocationDTO>>(Result);
            }

            return Location;
        }

        public IList<CountryDTO> GetCountry(int? CountryId, string CountryName)
        {
            IList<GetCountry_Result> Result = context.GetCountry(CountryId, string.IsNullOrEmpty(CountryName) ? null : CountryName).ToList();

            IList<CountryDTO> Country = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetCountry_Result, CountryDTO>();
                Country = Mapper.Map<IList<GetCountry_Result>, IList<CountryDTO>>(Result);
            }

            return Country;
        }

        public IList<RegionDTO> GetRegion(int? RegionId, string RegionName, int? CountryId)
        {
            IList<GetRegion_Result> Result = context.GetRegion(RegionId, string.IsNullOrEmpty(RegionName) ? null : RegionName, CountryId).ToList();

            IList<RegionDTO> Region = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetRegion_Result, RegionDTO>();
                Region = Mapper.Map<IList<GetRegion_Result>, IList<RegionDTO>>(Result);
            }

            return Region;
        }

        public IList<RoleDTO> GetRole(int? RoleId, string RoleName)
        {
            IList<GetRole_Result> Result = context.GetRole(RoleId, string.IsNullOrEmpty(RoleName) ? null : RoleName).ToList();

            IList<RoleDTO> Role = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetRole_Result, RoleDTO>();
                Role = Mapper.Map<IList<GetRole_Result>, IList<RoleDTO>>(Result);
            }

            return Role;
        }

        public IList<ParameterDTO> GetLanguages()
        {
            IList<GetParameter_Result> Result = context.GetParameter(9, 0, 0).ToList();

            IList<ParameterDTO> Languages = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetParameter_Result, ParameterDTO>();
                Languages = Mapper.Map<IList<GetParameter_Result>, IList<ParameterDTO>>(Result);
            }

            return Languages;
        }

        public IList<ParameterDTO> GetSalesChannel()
        {
            IList<GetParameter_Result> Result = context.GetParameter(10, 0, 0).ToList();

            IList<ParameterDTO> SalesChannel = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetParameter_Result, ParameterDTO>();
                SalesChannel = Mapper.Map<IList<GetParameter_Result>, IList<ParameterDTO>>(Result);
            }

            return SalesChannel;
        }
    }
}
