
import dotenv from 'dotenv';
import mongoose from 'mongoose';
import Doctor from '../models/Doctor';
import User from '../models/User';

dotenv.config();

const checkUser = async () => {
    try {
        await mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost:27017/clinic-management');
        console.log('Connected to MongoDB');

        const userId = '6993d82ab3529b1c04ae051c'; // The ID provided by the user (assuming it's a MongoDB ObjectId)

        // Check if ID is valid
        if (!mongoose.Types.ObjectId.isValid(userId)) {
            console.log(`Invalid ObjectId: ${userId}`);
            // It might be a string ID if not using default ObjectID, but let's assume it is.
            // If it's invalid, we can't query by _id if it's stored as ObjectId
        }

        const user = await User.findById(userId);
        if (user) {
            console.log('User found:', user);

            const doctor = await Doctor.findOne({ userId: user._id });
            if (doctor) {
                console.log('Doctor record found:', doctor);
            } else {
                console.log('Doctor record NOT found for this user.');
            }
        } else {
            console.log('User NOT found with ID:', userId);
        }

    } catch (error) {
        console.error('Error:', error);
    } finally {
        await mongoose.disconnect();
    }
};

checkUser();
