/**
 * Seed FAQs Script
 * Run this to populate initial FAQs in the database
 * 
 * Usage: node src/scripts/seedFAQs.js
 */

require('dotenv').config();
const mongoose = require('mongoose');
const FAQ = require('../models/FAQ');
const { connectDB } = require('../config/db.config');

const faqs = [
    // BOOKING CATEGORY
    {
        question: 'How can I book cheap cabs online?',
        answer: 'GoCabs helps you with online cab booking at the best prices, comparatively much lower than local vendors. You can compare prices from multiple service providers and choose the best option. Also, you can use promo codes and offers on the GoCabs website & app to get extra discounts on your online cab booking.',
        category: 'booking',
        order: 1,
        tags: ['booking', 'cheap', 'online', 'discount', 'promo'],
        metaDescription: 'Learn how to book cheap cabs online with GoCabs'
    },
    {
        question: 'What are the advantages of online taxi booking?',
        answer: 'Online taxi booking not only helps you with the best prices but also provides the convenience of paying through multiple payment options (like Debit Card, Credit Card, UPI, eWallets, etc.). You can easily compare prices and choose various categories of cabs like Hatchback cars, Sedan, and SUV. Additionally, you get confirmed bookings, verified drivers, and transparent pricing with no hidden charges.',
        category: 'booking',
        order: 2,
        tags: ['booking', 'online', 'advantages', 'payment'],
        metaDescription: 'Discover the advantages of online taxi booking'
    },
    {
        question: 'Why should you book cabs from GoCabs?',
        answer: 'From GoCabs you can get confirmed cheap cabs of your choice and budget. Expert and verified drivers will take care of your ride. Easy interface for booking with different payment modes available at GoCabs. Finally, with no hidden charges and transparent pricing, GoCabs is the best option for online taxi booking. We also provide 24/7 customer support and real-time tracking of your cab.',
        category: 'booking',
        order: 3,
        tags: ['gocabs', 'benefits', 'verified', 'transparent'],
        metaDescription: 'Why GoCabs is the best choice for cab booking'
    },
    {
        question: 'Do I need to register on GoCabs to book a cab online?',
        answer: 'No, you can successfully book a cab without registering on our website. However, creating an account helps you track your bookings, save favorite routes, and get personalized offers.',
        category: 'booking',
        order: 4,
        tags: ['registration', 'account', 'booking'],
        metaDescription: 'Learn about registration requirements for booking'
    },
    {
        question: 'What if the cab doesn\'t show up?',
        answer: 'If the vehicle you booked does not arrive at the scheduled time, we will immediately issue a complete refund. You can also contact our 24/7 customer support for immediate assistance and alternative arrangements.',
        category: 'booking',
        order: 5,
        tags: ['no-show', 'refund', 'support'],
        metaDescription: 'What happens if your booked cab doesn\'t arrive'
    },
    {
        question: 'What happens if the vehicle breaks down?',
        answer: 'Since we work with established service providers, the vehicles are usually reliable. In case of a breakdown, it is the service provider\'s responsibility to replace the vehicle during the journey. In case of any persisting issue, you may reach out to the helpline number provided by GoCabs, and we shall arrange an alternate cab for you immediately.',
        category: 'booking',
        order: 6,
        tags: ['breakdown', 'replacement', 'support'],
        metaDescription: 'Vehicle breakdown policy and support'
    },

    // VEHICLES CATEGORY
    {
        question: 'What are the best options available for cab booking?',
        answer: 'While booking cabs online through GoCabs, you can choose the car based on your requirement and preferences. You can book Hatchback like Indica, Swift, Wagon R; Sedan like Dzire, Etios, Honda City; and SUV like Innova, Ertiga, Scorpio. All vehicles are well-maintained and driven by verified drivers.',
        category: 'vehicles',
        order: 1,
        tags: ['vehicles', 'options', 'hatchback', 'sedan', 'suv'],
        metaDescription: 'Available vehicle options for cab booking'
    },
    {
        question: 'What kind of cabs can you book from GoCabs?',
        answer: 'You can book the following kinds of cabs from GoCabs: Airport cabs for airport transfers, Outstation cabs for intercity travel (both one-way and round-trip), and Rental cabs for hourly bookings within the city. All cab types are available in multiple vehicle categories.',
        category: 'vehicles',
        order: 2,
        tags: ['cab-types', 'airport', 'outstation', 'rental'],
        metaDescription: 'Types of cabs available on GoCabs'
    },
    {
        question: 'What are the popular outstation cab booking routes?',
        answer: 'Some of the popular outstation cab booking routes are: Pune to Mumbai cabs, Delhi to Jaipur cabs, Delhi to Agra cabs, Chennai to Pondicherry cabs, Ahmedabad to Vadodara cabs, Bangalore to Mysore cabs, Mumbai to Pune cabs, Hyderabad to Vijayawada cabs, and many more across India.',
        category: 'vehicles',
        order: 3,
        tags: ['outstation', 'routes', 'popular', 'intercity'],
        metaDescription: 'Popular outstation cab routes in India'
    },

    // PAYMENT CATEGORY
    {
        question: 'Can I book a cab without a credit card or net banking option?',
        answer: 'Yes, multiple payment options are available including UPI (GPay, PhonePe, Paytm), digital wallets (Paytm, Amazon Pay), debit cards, and cash payment to the driver. You can choose the most convenient payment method for you.',
        category: 'payment',
        order: 1,
        tags: ['payment', 'upi', 'wallet', 'cash', 'debit-card'],
        metaDescription: 'Payment options available for cab booking'
    },
    {
        question: 'What are the payment terms?',
        answer: 'You can confirm your reservation by paying a booking fee, typically 20-25% of the base fare. The balance can be paid online through our secure payment gateway until two days before the journey start, or you can pay the remaining amount to the driver in cash at the time of trip completion.',
        category: 'payment',
        order: 2,
        tags: ['payment', 'terms', 'advance', 'balance'],
        metaDescription: 'Payment terms and conditions for bookings'
    },

    // PRICING CATEGORY
    {
        question: 'How is the total cab fare calculated for an intercity cab service?',
        answer: 'For outstation trips (intercity), a specific number of kilometers are included in the base fare. Route-wise charges vary based on distance and vehicle type. The fare includes driver allowance and may include tolls and state taxes. Extra charges may apply for: waiting time, extra kilometers beyond included distance, night charges (10 PM - 6 AM), airport entry fees, parking charges, toll charges, and state taxes if not included in base fare.',
        category: 'pricing',
        order: 1,
        tags: ['pricing', 'intercity', 'outstation', 'fare'],
        metaDescription: 'How intercity cab fare is calculated'
    },
    {
        question: 'How is the total cab fare calculated for a local/rental cab service?',
        answer: 'Four rental packages are available: 4 hours & 40 km, 8 hours & 80 km, 12 hours & 120 km, and 24 hours & 300 km. The fare is fixed for the selected package. Extra kilometer charges and extra hour charges are applicable if your usage exceeds the package limits. All packages include driver allowance.',
        category: 'pricing',
        order: 2,
        tags: ['pricing', 'rental', 'local', 'packages'],
        metaDescription: 'Rental cab pricing and packages'
    },
    {
        question: 'How are the kilometers calculated?',
        answer: 'For outstation trips, kilometers are calculated based on the actual distance traveled from pickup to drop location. For round trips, the return journey distance is also included. For rental packages, the odometer reading is used to calculate the distance traveled during your booking period.',
        category: 'pricing',
        order: 3,
        tags: ['kilometers', 'distance', 'calculation'],
        metaDescription: 'How distance is calculated for cab bookings'
    },
    {
        question: 'How are tolls & taxes calculated?',
        answer: 'Tolls and interstate taxes are estimated based on the route. If these amounts are included in the fare, you will be charged or reimbursed for any difference between the actual costs and estimates. In some cases, tolls and taxes are paid directly by you to the driver, and these will be clearly mentioned in your booking details.',
        category: 'pricing',
        order: 4,
        tags: ['tolls', 'taxes', 'charges'],
        metaDescription: 'Toll and tax calculation policy'
    },

    // CANCELLATION CATEGORY
    {
        question: 'What if I need to cancel my trip?',
        answer: 'You can cancel your booking through the GoCabs website or app. The cancellation policy varies based on the vehicle group and time of cancellation. Generally, free cancellation is available if you cancel 48+ hours before pickup. Partial refunds apply for cancellations made 24-48 hours before pickup. Cancellation charges increase as you get closer to the pickup time. The exact refund amount will be shown before you confirm the cancellation.',
        category: 'cancellation',
        order: 1,
        tags: ['cancellation', 'refund', 'policy'],
        metaDescription: 'Cab booking cancellation policy and refunds'
    },

    // GENERAL CATEGORY
    {
        question: 'Is customer support available 24/7?',
        answer: 'Yes, GoCabs provides 24/7 customer support through phone, email, and in-app chat. Our support team is always ready to assist you with bookings, cancellations, or any issues during your journey.',
        category: 'general',
        order: 1,
        tags: ['support', '24/7', 'customer-service'],
        metaDescription: 'GoCabs customer support availability'
    },
    {
        question: 'Are the drivers verified?',
        answer: 'Yes, all drivers on the GoCabs platform are thoroughly verified. We conduct background checks, verify driving licenses, and ensure all drivers have proper documentation. Driver ratings and reviews from previous customers are also available to help you make informed decisions.',
        category: 'general',
        order: 2,
        tags: ['drivers', 'verified', 'safety'],
        metaDescription: 'Driver verification and safety measures'
    },
    {
        question: 'Can I track my cab in real-time?',
        answer: 'Yes, once your booking is confirmed and the driver is assigned, you can track your cab in real-time through the GoCabs app. You will receive the driver\'s details, vehicle information, and live location updates.',
        category: 'general',
        order: 3,
        tags: ['tracking', 'real-time', 'live-location'],
        metaDescription: 'Real-time cab tracking feature'
    }
];

async function seedFAQs() {
    try {
        // Connect to database
        await connectDB();
        console.log('Connected to database');

        // Clear existing FAQs (optional - comment out if you want to keep existing)
        // await FAQ.deleteMany({});
        // console.log('Cleared existing FAQs');

        // Insert FAQs
        const result = await FAQ.insertMany(faqs);
        console.log(`✅ Successfully inserted ${result.length} FAQs`);

        // Show summary by category
        const summary = await FAQ.aggregate([
            { $group: { _id: '$category', count: { $sum: 1 } } },
            { $sort: { _id: 1 } }
        ]);

        console.log('\n📊 FAQs by Category:');
        summary.forEach(cat => {
            console.log(`   ${cat._id}: ${cat.count} FAQs`);
        });

        process.exit(0);
    } catch (error) {
        console.error('❌ Error seeding FAQs:', error);
        process.exit(1);
    }
}

// Run the seed function
seedFAQs();
