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

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WK_KLI_LAPS_Service.Controllers.Master.Project
{

    public interface IProjectService
    {
        object GetAll();
        object GetActiveProject();
        int Add(projectModel data);
        int Edit(projectModel data);
        int Delete(projectModel data);
        object GetActiveCustomer();
        object GetContactByCustomerId(projectModel data);
        object GetActiveCustomerContact();
    }
    public class ProjectService : IProjectService
    {
        MasterRepository oMasterRepository = new MasterRepository();
        CommonRepository oCommonRepository = new CommonRepository();

        //code to retrieve list of all project details
        public object GetAll()
        {
            return oMasterRepository.GetAll("project");
        }
        //code to retrieve list of active project details
        public object GetActiveProject()
        {

            return oMasterRepository.GetActive("project");
        }
        //Code to add new  project details
        public int Add(projectModel data)
        {
            if (string.IsNullOrEmpty(data.projectname))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.add(data, "project");
            return retval;
        }

        //code to update  project details
        public int Edit(projectModel data)
        {
            if (string.IsNullOrEmpty(data.projectname))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.Edit(data, "project");
            return retval;
        }
        //code to activate or deactivate record
        public int Delete(projectModel data)
        {
            int retval = oMasterRepository.Delete(data, "project");
            return retval;
        }
        //code to retrieve list of active project details
        public object GetActiveCustomer()
        {
            return oMasterRepository.GetActive("customer");
        }

        //code to retrieve list of customer contact details by customer id
        public object GetContactByCustomerId(projectModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            // return oProjectConfigurationRepository.GetContactByCustomerId(input);
            return oCommonRepository.ExecuteSP_ReturnList("public.spcustomercontactselect", input, "getbycustomerid");
        }

        //code to retrieve list of active project details
        public object GetActiveCustomerContact()
        {
            //return oProjectConfigurationRepository.GetActiveCustomerContact();
            return oCommonRepository.ExecuteSP_ReturnList("public.spcustomercontactselect", null, "getactive");
        }
    }
}
