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

namespace WK_KLI_LAPS_Service.Controllers.UserManagement.EmailMapping
{
    public interface IUserMailMappingService
    {
        object GetAll();
        object FindAllOrActiveMenus();
        object GetById(Int64 data, string mode);
        object getActionLst();
        object Add(string inputstr, string mode);
        object Update(string inputstr, string mode);
        int Delete(usermailmappingModel data);
    }
    public class UserMailMappingService : IUserMailMappingService
    {
        MasterRepository oMasterRepository = new MasterRepository();
        CommonRepository oCommonRepository = new CommonRepository();
        //code to retrieve list of all active role list
        public object GetAll()
        {
            return oMasterRepository.GetAll("role");
        }
        //code to retrieve list of all records
        public object FindAllOrActiveMenus()
        {
            return oMasterRepository.GetActive("menu");
        }
        //code to retrieve list of actions available 
        public object getActionLst()
        {
            return oCommonRepository.getActionList();
        }
        //Code to add new role details 

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

        //code to update role details
        public object Update(string inputstr, string mode)
        {
            //    if (string.IsNullOrEmpty(data.rolename))
            //        throw new Exception("Value should not be empty");
            string query = @"public.spusermailtemplatemapping";
            return oCommonRepository.ExecuteSP_ReturnList(query, inputstr, mode);
        }
        //code to retrieve list of all records
        public object GetById(Int64 data, string mode)
        {
            var userrolemapping = new { mailtemplateid = data };
            var jsonstr = JsonConvert.SerializeObject(userrolemapping);
            string query = @"public.spusermailtemplatemappingselect";
            return oCommonRepository.ExecuteSP_ReturnList(query, jsonstr, mode);
        }

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

    }
}