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

namespace WK_KLI_LAPS_Service.Controllers.Master.Plugin
{
    public interface IPluginService
    {
        object GetAll();
        object GetActivePlugin();
        int Add(pluginModel data);
        int Edit(pluginModel data);
        int Delete(pluginModel data);
    }
    public class PluginService : IPluginService
    {
        MasterRepository oMasterRepository = new MasterRepository();

        //code to retrieve list of all records
        public object GetAll()
        {
            return oMasterRepository.GetAll("plugin");
        }

        //code to retrieve list of active records
        public object GetActivePlugin()
        {
            return oMasterRepository.GetActive("plugin");
        }

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

        //code to update data
        public int Edit(pluginModel data)
        {
            if (string.IsNullOrEmpty(data.plugin))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.Edit(data, "plugin");
            return retval;
        }

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