{ console.log(`Order placed at "${restaurant}".`); callback(null, restaurant); }, 1000); // simulate async ordering } // Step 3: Process payment function processPayment(restaurant, callback) { setTimeout(() => { const paymentSuccess = true; // Change to false to simulate failure if (paymentSuccess) { console.log('Payment successful.'); callback(null, restaurant); } else { callback('Error: Payment failed.'); } }, 1000); // simulate async payment } // Step 4: Confirm delivery function confi"> { console.log(`Order placed at "${restaurant}".`); callback(null, restaurant); }, 1000); // simulate async ordering } // Step 3: Process payment function processPayment(restaurant, callback) { setTimeout(() => { const paymentSuccess = true; // Change to false to simulate failure if (paymentSuccess) { console.log('Payment successful.'); callback(null, restaurant); } else { callback('Error: Payment failed.'); } }, 1000); // simulate async payment } // Step 4: Confirm delivery function confi"> { console.log(`Order placed at "${restaurant}".`); callback(null, restaurant); }, 1000); // simulate async ordering } // Step 3: Process payment function processPayment(restaurant, callback) { setTimeout(() => { const paymentSuccess = true; // Change to false to simulate failure if (paymentSuccess) { console.log('Payment successful.'); callback(null, restaurant); } else { callback('Error: Payment failed.'); } }, 1000); // simulate async payment } // Step 4: Confirm delivery function confi">
function searchRestaurant(name, callback) {
  setTimeout(() => {
    const restaurants = ['Pizza Hut', 'Dominoes', 'Burger King'];
    if (restaurants.includes(name)) {
      console.log(`Restaurant "${name}" found.`);
      callback(null, name);
    } else {
      callback(`Error: Restaurant "${name}" not found.`);
    }
  }, 1000); // simulate async DB search
}

// Step 2: Place the order
function placeOrder(restaurant, callback) {
  setTimeout(() => {
    console.log(`Order placed at "${restaurant}".`);
    callback(null, restaurant);
  }, 1000); // simulate async ordering
}

// Step 3: Process payment
function processPayment(restaurant, callback) {
  setTimeout(() => {
    const paymentSuccess = true; // Change to false to simulate failure
    if (paymentSuccess) {
      console.log('Payment successful.');
      callback(null, restaurant);
    } else {
      callback('Error: Payment failed.');
    }
  }, 1000); // simulate async payment
}

// Step 4: Confirm delivery
function confirmDelivery(restaurant, callback) {
  setTimeout(() => {
    console.log(`Delivery confirmed for "${restaurant}" order.`);
    callback(null, `Order completed successfully at "${restaurant}".`);
  }, 1000); // simulate async delivery confirmation
}

// main.js
const foodApp = require('./foodApp');

const restaurantName = 'Pizza Hut';

foodApp.searchRestaurant(restaurantName, (err, restaurant) => {
  if (err) {
    return console.error(err);
  }

  foodApp.placeOrder(restaurant, (err, restaurant) => {
    if (err) {
      return console.error(err);
    }

    foodApp.processPayment(restaurant, (err, restaurant) => {
      if (err) {
        return console.error(err);
      }

      foodApp.confirmDelivery(restaurant, (err, message) => {
        if (err) {
          return console.error(err);
        }
        console.log(message);
      });
    });
  });
});