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

namespace WK_KLI_LAPS_Service.Controllers.CheckListDetails
{

    public interface ICheckListDetailsService
    {
        object GetAll(int checklistid);
        object GetActiveCheckList();
        object GetCheckList();
        int Add(checklistdetailsModel data);
        int Edit(checklistdetailsModel data);
        int Delete(checklistdetailsModel data);

    }

    public class CheckListDetailsService : ICheckListDetailsService
    {
        CheckListDetailsRepository oCheckListDetailsRepository = new CheckListDetailsRepository();
        MasterRepository oMasterRepository = new MasterRepository();

        public int Add(checklistdetailsModel data)
        {
            if (string.IsNullOrEmpty(data.checklistdetail))
                throw new Exception("Value should not be empty");
            int retval = oCheckListDetailsRepository.add(data, "checklistdetail");
            return retval;
        }

        public int Delete(checklistdetailsModel data)
        {
            int retval = oCheckListDetailsRepository.Delete(data, "checklistdetail");
            return retval;
        }

        public int Edit(checklistdetailsModel data)
        {
            if (string.IsNullOrEmpty(data.checklistdetail))
                throw new Exception("Value should not be empty");
            int retval = oCheckListDetailsRepository.Edit(data, "checklistdetail");
            return retval;
        }

        public object GetActiveCheckList()
        {
            return oCheckListDetailsRepository.GetActive("checklistdetail");
        }

        /// Get the list of all master data present in the db
        public object GetAll(int checklistid)
        {
            return oCheckListDetailsRepository.GetAll("checklistdetail", checklistid);
        }

        public object GetCheckList()
        {
            return oMasterRepository.GetActive("checklist");

        }
    }
}
