const dbConnect = require('../configs/dbConnection.js');

// GET /agent/services?uid=6
exports.getServices = async (req, res) => {
  try {
    const { uid } = req.query;

    if (!uid) {
      return res.status(400).json({ error: 'uid is required' });
    }

    // Services row fetch
    const [rows] = await dbConnect.query(
      `SELECT bus, flights, hotels, holidays, cabs, bill_payments, it_services
       FROM agent_services WHERE uid = ?`,
      [uid]
    );

    if (rows.length === 0) {
      return res.status(404).json({ error: 'No services found for this user' });
    }

    return res.status(200).json({
      uid: Number(uid),
      services: rows[0],
    });

  } catch (error) {
    console.error('[agentServices] Error:', error.message);
    return res.status(500).json({ error: 'Failed to fetch services' });
  }
};