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

namespace BusinessLayer
{
    public class DSRManager : BLBase
    {
        public void InsertUpdateDSRHeader(DateTime Date, string Shift, TimeSpan? MorningIn, TimeSpan? MorningOut,
                                          TimeSpan? EveningIn, TimeSpan? EveningOut, string Comments, int UserId)
        {
            context.InsertUpdateDSRHeader(null, Date, Shift, MorningIn, MorningOut, EveningIn, EveningOut, Comments, UserId);
        }

        public IList<ActiveDsrContactCustomerLocationDTO> GetDsrContactCustomerLocation(int User_Id, DateTime Date)
        {
            IList<GetActiveDsrContactCustomerLocation_Result> Result = context.GetActiveDsrContactCustomerLocation(User_Id, Date).ToList();

            IList<ActiveDsrContactCustomerLocationDTO> output = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetActiveDsrContactCustomerLocation_Result, ActiveDsrContactCustomerLocationDTO>();
                output = Mapper.Map<IList<GetActiveDsrContactCustomerLocation_Result>, IList<ActiveDsrContactCustomerLocationDTO>>(Result);
            }

            return output;
        }

        public DSRHeaderDTO GetDsrHeader(int User_Id, DateTime Date)
        {
            GetDSRHeader_Result Result = context.GetDSRHeader(null, Date, null, null, null, null, null, null, User_Id).FirstOrDefault();

            DSRHeaderDTO DsrHeader = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetDSRHeader_Result, DSRHeaderDTO>();
                DsrHeader = Mapper.Map<GetDSRHeader_Result, DSRHeaderDTO>(Result);
            }

            return DsrHeader;
        }

        public DSRDTO GetDSR(int DSRId)
        {
            GetDSR_Result Result = context.GetDSR(DSRId, null, null, null, null, null, null, null, null, null, null, null, null, null, null).FirstOrDefault();

            DSRDTO DSR = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetDSR_Result, DSRDTO>();
                DSR = Mapper.Map<GetDSR_Result, DSRDTO>(Result);
            }

            return DSR;
        }
    }
}
