const tripDetailsModel = require('../model/tripDetailsModel');

exports.getTripDetails = async (req, res) => {


    try {
        
        const { id } = req.query;
       
        if (!id) {
            return res.status(400).json({ error: "id is required" });
        }

        const trimmedId = id.trim();
        
        req.session.bus_booking.busId = trimmedId;

        const tripsData = await tripDetailsModel.fetchTripDetails(trimmedId);

        if (!tripsData || tripsData.length === 0) {
            return res.status(404).json({ error: 'No trips available for the given parameters' });
        }

        res.json(tripsData);
    }
    catch (error) {
        //console.error('Error fetching available trips:', error.message);
        res.status(404).json({ error: 'Failed to fetch available trips' });
    }

};