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

namespace WK_KLI_LAPS_Service.Controllers.Master.Feature
{
    public interface IFeatureService
    {
        object GetAll();
        object GetActivemetadata();
        int Add(featureModel data);
        int Edit(featureModel data);
        int Delete(featureModel data);
        object GetById(featureModel data);
    }

    public class FeatureService : IFeatureService
    {
        MasterRepository oMasterRepository = new MasterRepository();
        public object GetAll()
        {
            return oMasterRepository.GetAll("feature");
        }

        public object GetActivemetadata()
        {
            return oMasterRepository.GetActive("feature");
        }

        public int Add(featureModel data)
        {
            if (string.IsNullOrEmpty(data.mdata))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.add(data, "feature");
            return retval;
        }
        public int Edit(featureModel data)
        {
            if (string.IsNullOrEmpty(data.mdata))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.Edit(data, "feature");
            return retval;
        }
        public object GetById(featureModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oMasterRepository.GetById("metadata", input);
        }

        public int Delete(featureModel data)
        {
            int retval = oMasterRepository.Delete(data, "feature");
            return retval;
        }
    }
}
