using BPMService.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using WK_KLI_LAPS_Service.App_Data;
using WK_KLI_LAPS_Service.Models;

namespace WK_KLI_LAPS_Service.Controllers.Dashboard
{
    public interface IDashboardService
    {
        object getUserProjectStatusDetails(string data);
        object getJobNo(string data);
        object loadStageDetails(string data);
        object getMailBoxDetails(string data);
        object getLoadType(string data);
        object getVendorUser(string data);
        object getProjectJobDetails(string data);
        object getStageList(string data);
        object getUserAssignedJob(string data);
        object getavailablelot(string data);
        object getassignedvendorlot(string data);
        object getUserAssignedUser(string data);
        int jobBackForward(object data);
        object getUserAssignedLot(string data);
        object GetUserWiseAssignLot(lotassignmentdetails data);
        object setLotAssignDetails(string data);
        object getUserJobs(string data);
        object usrstagemove(object data);
        object usrLotTransactionInsert(string userid, string lotid, string jobworkflowid, string transkey, string mode);
        int Delete(object data);
        object getcheckexisttranbywflotid(string data,string mode);
        object getLotCommentsByProject(string data);
    }
    public class DashboardService : IDashboardService
    {
        CommonRepository oCommonRepository = new CommonRepository();
        DashboardRepository oDashboardRepository = new DashboardRepository();
        MasterRepository oMasterRepository = new MasterRepository();
        //code to retrieve list of all records
        public object getUserProjectStatusDetails(string data)
        {

            return oCommonRepository.ExecuteSP_ReturnList("spdashboardselect", data, "getuserprojectstatusdetails");
        }
        public object getJobNo(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spdashboardselect", data, "getjobno");
        }
        //tas
        //public object loadStageDetails(string data)
        //{
        //    return oDashboardRepository.getJobStatusReport("spgetjobstatusreportstjob", data);
        //}
        public object loadStageDetails(string data)
        {
            //string inputstr = JsonConvert.SerializeObject(data);
            var result = JsonConvert.DeserializeObject<jobStatus>(data);
            return CommonRepository.ExecuteSP_ReturnList2("spgetjobstatusreportstjob", data, result.mode);          
            //return oDashboardRepository.getJobStatusReport("spgetjobstatusreportstjob_duplicate", inputstr);
        }
        public object getMailBoxDetails(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spmailboxselect", data, "getMailBox");
        }
        public object getLoadType(string data)
        {
            return oDashboardRepository.getLoadType("spuserrolemappingselect", data, "getuseraspm");
        }
        public object getProjectJobDetails(string data)
        {
            var projectJobDetails = oDashboardRepository.getProjectJobDetails("spgetlots", data);
            var isPushStage = oCommonRepository.ExecuteSP_ReturnList("spgetpushstage", data, "isPushstage");
            var json = new List<object>();
            json.Add(isPushStage);
            json.Add(projectJobDetails);
            return json;
        }
        public object getStageList(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spdashboardselect", data, "getstagelist");
        }
        public object getUserAssignedJob(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spdashboardselect", data, "getuserassignedjob");
        }
        public object getavailablelot(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("splotmasterselect", data, "getavailablebyjobid_vendor");
        }
        public object getassignedvendorlot(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("splotmasterselect", data, "getassignedbyjobid_vendor");
        }
        public object getUserAssignedUser(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spdashboardselect", data, "getuserassigneduser");
        }public object getVendorUser(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spdashboardselect", data, "getvendoruser");
        }
        public object getcheckexisttranbywflotid(string data,string mode)
        {
            return oCommonRepository.Vendor_ExecuteSP_ReturnList1("splottransactionselect", data, mode);
        }
        public int jobBackForward(object data)
        {
            //return oCommonRepository.ExecuteSP_ReturnInt("spjobbackforward", data, null, "jobBackForward");
            return oCommonRepository.ExecuteSP_ReturnInt("spjobbackforward", data, null, "jobBackForward");
        }
        public object GetUserWiseAssignLot(lotassignmentdetails data)
        {
            var input = JsonConvert.SerializeObject(data);
           return oCommonRepository.ExecuteSP_ReturnList("spgetuserwiseassignlot", input, data.mode);
			 // return oCommonRepository.ExecuteSP_ReturnList("spgetuserwiseassignlot_new", input, data.mode); //monicaa. once done rename sp
        }
        public object getUserAssignedLot(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spdashboardselect", data, "getuserassignedlot");
        }
        public object setLotAssignDetails(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spusrlotassigndetails", data, "");
        }
        public object getUserJobs(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spdashboardselect", data, "getuserjobs");
        }
        public object usrstagemove(object data)
        {
            var input = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnListwithoutmode("spusrstagemove", input);
        }
        public object usrLotTransactionInsert(string userid, string lotid, string jobworkflowid, string transkey, string mode)
        {
            insertcomments oInsertComments = new insertcomments();
            oInsertComments.userid = Convert.ToUInt32(userid);
            oInsertComments.lotid = Convert.ToUInt32(lotid);
            oInsertComments.transactionkey = transkey;
            oInsertComments.jobworkflowid = Convert.ToUInt32(jobworkflowid);
            oInsertComments.p_option = mode;
            var input = JsonConvert.SerializeObject(oInsertComments);
            return oCommonRepository.ExecuteSP_ReturnList1("spusrlottransactionupdate", input);
        }
        public int Delete(object data)
        {
            int retval = oMasterRepository.Delete(data, "mailbox");
            return retval;
        }
        //code to update data
        public int UpdateMailbox(object data)
        {

            int retval = oCommonRepository.UpdateMailbox(data, "mailbox");
            return retval;
        }
        public object getjoblotexcel(string data, string mode)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spjoblotexcelmasterselect", data, mode);
        }
        //Code to add data
        public object Add(string inputstr, string mode)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spjoblotexcelmaster", inputstr, mode);
        }
        public object getLotCommentsByProject(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spgetlotcommentsbyproject", data, "select");
        }
    }
}
