  const { fetchContacts, fetchCallList } = require('../services/apiService');

  async function getContacts(req, res) {
    try {
      const data = await fetchContacts();
      res.json(data);
    } catch (err) {
      res.status(500).json({ error: err.message });
    }
  }

  async function getCallList(req, res) {

    const { assignedTo,call_id } = req.body || {};

    if (!assignedTo && !call_id) {
      return res.status(400).json({ error: "Missing assignedTo or call_id" });
    }

    
    try {
      const data = await fetchCallList({assignedTo,call_id});
      res.json(data);
    } catch (err) {
      res.status(500).json({ error: err.message });
    }
  }

  module.exports = { getContacts, getCallList };