const flightStatusService = require("../services/flightStatusService");

exports.getFlightStatus = async (req, res) => {
  try {
    const { carrier, flightNumber, date } = req.query;

    if (!carrier || !flightNumber || !date) {
      return res.status(400).json({
        error: "carrier, flightNumber, and date are required",
      });
    }

    const result = await flightStatusService.getFlightStatus({
      carrier,
      flightNumber,
      date,
    });

    return res.status(200).json(result);
  } catch (error) {
    console.error("Flight Status Error:", error.message);

    return res.status(500).json({
      error: "Failed to fetch flight status",
    });
  }
};
