using Newtonsoft.Json;
using WK_KLI_LAPS_Service.App_Data;

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

namespace WK_KLI_LAPS_Service.Controllers.UserManagement.StageMapping
{
    public interface IStageMappingService
    {
        object GetAll();
        object Add(string inputstr, string mode);
        object GetById(int data, string mode);
        object UpdateUserProjectOnEmpty(string inputstr, string mode);
        object GetProjectMappingUsers(int data, string mode);
        object GetUserStagemappingDetails(int stagemappingid, int userid, int Pwdid);
    }

    public class StageMappingService : IStageMappingService
    {
        CommonRepository oCommonRepository = new CommonRepository();
        public object GetAll()
        {
            return oCommonRepository.ExecuteSP_ReturnList("spprojectworkflowdefinitionselect", null, "getall");
        }

        public object Add(string inputstr, string mode)
        {
            string query = @"public.spuserstagemapping";
            return oCommonRepository.ExecuteSP_ReturnList(query, inputstr, mode);
        }

        public object GetById(int data, string mode)
        {
            var userrolemapping = new { pwdid = data };
            var jsonstr = JsonConvert.SerializeObject(userrolemapping);
            string query = @"public.spuserstagemappingselect";
            return oCommonRepository.ExecuteSP_ReturnList(query, jsonstr, mode);
        }

        public object UpdateUserProjectOnEmpty(string inputstr, string mode)
        {
            return oCommonRepository.ExecuteSP_ReturnList("spuserstagemappingselect", inputstr, mode);
        }
        public object GetProjectMappingUsers(int data, string mode)
        {
            var userrolemapping = new { userid = data };
            var jsonstr = JsonConvert.SerializeObject(userrolemapping);
            string query = @"public.spuserstagemappingselect";
            return oCommonRepository.ExecuteSP_ReturnList(query, jsonstr, mode);
        }
        public object GetUserStagemappingDetails(int stagemappingid, int userid, int Pwdid)
        {
            var userstagemapDetails = new { userid = userid, pwdid = Pwdid, userstagemappingid = stagemappingid };
            var jsonstr = JsonConvert.SerializeObject(userstagemapDetails);
            string query = @"public.spuserstagemappingselect";
            string mode = "getserstagemapingdetailsby_S_U_P";
            return oCommonRepository.ExecuteSP_ReturnList(query, jsonstr, mode);

        }
    }
}
