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.WorkFlow
{
    public interface IWorkFlowConfigurationService
    {
        // object GetAll();
        // object GetActiveMenu();
        object Add(workflowdefinitionModel data);
        // int Edit(workflowdefinitionModel data);
        object Delete(workflowdefinitionModel data);
        object Edit(string inputstr, string mode);
        object GetFlowChart(workflowdefinitionModel data);
        object GetById(workflowdefinitionModel data, string mode);
        object UpdateInOutFile(string inputstr, string mode);
        object IOGetByWfdId(inoutfileModel data, string mode);
    }
    public class WorkFlowConfigurationService : IWorkFlowConfigurationService
    {
        WorkFlowConfigurationRepository oWorkFlowConfigurationRepository = new WorkFlowConfigurationRepository();
        CommonRepository oCommonRepository = new CommonRepository();

        public object Add(workflowdefinitionModel data)
        {
            if (string.IsNullOrEmpty(data.stagename_alias))
                throw new Exception("Value should not be empty");
            return oWorkFlowConfigurationRepository.add(data);
        }

        //code to activate or deactivate record
        public object Delete(workflowdefinitionModel data)
        {
            return oWorkFlowConfigurationRepository.Delete(data);

        }

        //code to update stage movement details
        public object Edit(string inputstr, string mode)
        {
            return oWorkFlowConfigurationRepository.Edit(inputstr, mode);

        }

        //code to get flowchart for the given workflow definition
        public object GetFlowChart(workflowdefinitionModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList("spworkflowdefinitionselect", input, "getflowchart");
        }

        //method to retrieve the workflow definition details based on workflow id
        public object GetById(workflowdefinitionModel data, string mode)
        {
            string input = JsonConvert.SerializeObject(data);
            return oWorkFlowConfigurationRepository.GetById(input, mode);
        }


        public object UpdateInOutFile(string inputstr, string mode)
        {
            return oWorkFlowConfigurationRepository.UpdateInOutFile(inputstr, mode);
        }

        //method to retrieve the inputoutputfile details based on workflow id
        public object IOGetByWfdId(inoutfileModel data, string mode)
        {
            string input = JsonConvert.SerializeObject(data);
            return oWorkFlowConfigurationRepository.IOGetByWfdId(input, mode);
        }
    }
}
