using Newtonsoft.Json;
using WK_KLI_LAPS_Service.App_Data;

namespace WK_KLI_LAPS_Service.Controllers.Common.Uploader
{
    public interface IUploaderService
    {
        object getlotsdetailsbytrankey(string trankey);
        object getlotsassignmentlotdetails(int jobworkflowid, int lotid, int userid);
        object getlotsassignmentbatchdetails(int jobworkflowid, int batchid, int userid);
        object updatelotstatusbytrankey(string trankey, int userid, string lotstatus);
        object getstagename(int jobworkflowid);
        object getjobtitle(int lotid);
        object getjobid(int batchid);
        object gettransactionid(string trankey);
        object getlotstatusbytrankey(string trankey);
        object usremailinfojob(int lotid, int jobworkflowid);
        object getJobDetails(string trankey);
    }


    public class UploaderService : IUploaderService
    {
        CommonRepository oCommonRepository = new CommonRepository();

        public object getlotsdetailsbytrankey(string trankey)
        {
            var data = new { trankey = trankey, p_option = "getlotsdetailsbytrankey" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }

        public object getlotsassignmentlotdetails(int jobworkflowid, int lotid, int userid)
        {
            var data = new { jobworkflowid = jobworkflowid, lotid = lotid, userid = userid, p_option = "getlotsassignmentlotdetails" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }

        public object getlotsassignmentbatchdetails(int jobworkflowid, int batchid, int userid)
        {
            var data = new { jobworkflowid = jobworkflowid, batchid = batchid, userid = userid, p_option = "getlotsassignmentbatchdetails" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }

        public object updatelotstatusbytrankey(string trankey, int userid, string lotstatus)
        {
            var data = new { trankey = trankey, p_option = "updatelotstatusbytrankey", lotstatus = lotstatus, userid = userid };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }

        public object getstagename(int jobworkflowid)
        {
            var data = new { jobworkflowid = jobworkflowid, p_option = "getstagename" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }
        public object getjobtitle(int lotid)
        {
            var data = new { lotid = lotid, p_option = "getjobtitle" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }

        public object getjobid(int batchid)
        {
            var data = new { batchid = batchid, p_option = "getjobid" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }

        public object gettransactionid(string trankey)
        {
            var data = new { trankey = trankey, p_option = "gettransactionid" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }

        public object getlotstatusbytrankey(string trankey)
        {
            var data = new { trankey = trankey, p_option = "getlotstatusbytrankey" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }
        public object getlotstatusbyvendorkey(string trankey)
        {
            var data = new { trankey = trankey, p_option = "getlotstatusbytrankey" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("sppostupdatelottransaction", jsonstr);
        }
        public string GetServerPath(string id, bool createdir, string mode)
        {
            string fileSaveLocation = oCommonRepository.GetServerPath(id, mode, createdir);
            return fileSaveLocation;
        }

        public object usremailinfojob(int lotid, int jobworkflowid)
        {
            var data = new { tranid = lotid, jobworkflowid = jobworkflowid, p_option = "1" };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("spusrusremailinfojobv1", jsonstr);
        }

        public object getJobDetails(string trankey)
        {
            var data = new { trankey = trankey };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList1("spgetjobdetailstrankey", jsonstr);
        }
    }
}
