using Newtonsoft.Json;
using System;
using WK_KLI_LAPS_Service.App_Data;
using WK_KLI_LAPS_Service.Models.Configuration;


namespace WK_KLI_LAPS_Service.Controllers.Master.Lot
{

    public interface ILotService
    {
        object GetAll();
        object GetActiveLot();
        object Add(string inputstr, string mode);
        int Edit(lotmasterModel data);
        int Delete(lotmasterModel data);
        object GetByJobId(lotmasterModel data);
        object GetBylotProjectId(lotmasterModel data);
        object GetBylotId(lotmasterModel data);
        lotmasterModel GetServerPath(string data);
        object GetCommentsByTranId(lotcomment data);
        object AddCCLotMaster(lotmasterModel olotmaster, string spname);
    }

    public class LotService : ILotService
    {
        MasterRepository oMasterRepository = new MasterRepository();
        CommonRepository oCommonRepository = new CommonRepository();
        //code to retrieve list of all records
        public object GetAll()
        {

            return oMasterRepository.GetAll("lot");
        }

        //code to retrieve list of active records
        public object GetActiveLot()
        {

            return oMasterRepository.GetActive("lot");
        }

        //Code to add data
        public object Add(string inputstr, string mode)
        {
            return oCommonRepository.ExecuteSP_ReturnList("splotmaster", inputstr, mode);

        }
        public object GetBylotId(lotmasterModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList("splotmasterselect", input, "getbylotid");
        }
        //code to update data
        public int Edit(lotmasterModel data)
        {
            if (string.IsNullOrEmpty(data.title))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.Edit(data, "lot");
            return retval;
        }

        //code to activate or deactivate record
        public int Delete(lotmasterModel data)
        {
            int retval = oMasterRepository.Delete(data, "lot");
            return retval;
        }

        public object GetByJobId(lotmasterModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList("splotmasterselect", input, "getbyjobid");
        }
        public object GetBylotProjectId(lotmasterModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList("splotmasterselect", input, "getbylotdataprojectid");
        }

        public lotmasterModel GetServerPath(string data)
        {
            return oCommonRepository.ExecuteSP_ReturnListForLot("spusrserverpathinfo", data, "serverinfo_job");
        }
        public object GetCommentsByTranId(lotcomment data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList("splotmasterselect", input, "getcommentsbytranid");
        }
        //ccwms
        public object AddCCLotMaster(lotmasterModel olotmasterr, string spname)
        {
            return oCommonRepository.CCExecuteSP_ReturnList1(spname, olotmasterr);
        }
    }

}
