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.Configuration.Outline.Outline
{
    public interface IOutlineService
    {
        object GetAll();
        object GetAllByUserid(outlineModel data);
        object GetActiveOutline();
        object SaveAsOutline(string inputstr);
        int Add(outlineModel data);
        int Edit(outlineModel data);
        int Delete(outlineModel data);
        object GetById(outlineModel data);
        object getAllByIdForStatusCheck(outlineModel data);
    }
    public class OutlineService : IOutlineService
    {
        MasterRepository oMasterRepository = new MasterRepository();
        CommonRepository oCommonRepository = new CommonRepository();
        //code to retrieve list of all records
        public object GetAll()
        {
            return oCommonRepository.ExecuteSP_ReturnList("spoutlineconfigselect", null, "getall");
        }

        public object GetAllByUserid(outlineModel data)
        {
            string inputstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList("spoutlineconfigselect", inputstr, "getAllByUserid");
        }
        //code to retrieve list of active records
        public object GetActiveOutline()
        {
            return oCommonRepository.ExecuteSP_ReturnList("spoutlineconfigselect", null, "getall");
        }

        public object SaveAsOutline(string inputstr)
        {

            var retval = oCommonRepository.ExecuteSP_ReturnList("spoutlineconfig", inputstr, "saveas");
            return retval;
        }

        //Code to add data
        public int Add(outlineModel data)
        {
            if (data.projectid < 0)
                throw new Exception("Value should not be empty");
            int retval = oCommonRepository.ExecuteSP_ReturnInt("spoutlineconfig", data, "insert", "Add new outline");
            return retval;
        }

        //code to update data
        public int Edit(outlineModel data)
        {
            if (data.projectid < 0)
                throw new Exception("Value should not be empty");
            int retval = oCommonRepository.ExecuteSP_ReturnInt("spoutlineconfig", data, "update", "update outline");
            return retval;
        }

        //code to activate or deactivate record
        public int Delete(outlineModel data)
        {
            int retval = oCommonRepository.ExecuteSP_ReturnInt("spoutlineconfig", data, "activeordeactive", "Delete outline");
            return retval;
        }
        public object GetById(outlineModel data)
        {
            string inputstr = JsonConvert.SerializeObject(data);
            var retval = oCommonRepository.ExecuteSP_ReturnList("spoutlineconfigselect", inputstr, "getbyid");
            return retval;
        }
        public object getAllByIdForStatusCheck(outlineModel data)
        {
            string inputstr = JsonConvert.SerializeObject(data);
            var retval = oCommonRepository.ExecuteSP_ReturnList("spoutlineconfigselect", inputstr, "getAllByIdForStatusCheck");
            return retval;
        }
    }
}
