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.SubSkill
{
    public interface ISubSkillService
    {
        object GetAll();
        object GetById(subskillModel data);
        object GetActiveSubSkill();
        int Add(subskillModel data);
        int Edit(subskillModel data);
        int Delete(subskillModel data);
    }
    public class SubSkillService : ISubSkillService
    {

        MasterRepository oMasterRepository = new MasterRepository();

        public int Add(subskillModel data)
        {
            if (string.IsNullOrEmpty(data.subskillname))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.add(data, "subskill");
            return retval;
        }

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

        public int Edit(subskillModel data)
        {
            if (string.IsNullOrEmpty(data.subskillname))
                throw new Exception("Value should not be empty");
            int retval = oMasterRepository.Edit(data, "subskill");
            return retval;
        }

        public object GetActiveSubSkill()
        {
            return oMasterRepository.GetActive("subskill");
        }

        public object GetAll()
        {
            return oMasterRepository.GetAll("subskill");
        }

        public object GetById(subskillModel data)
        {
            string input = JsonConvert.SerializeObject(data);
            return oMasterRepository.GetById("subskill", input);
        }
    }
}
