
import dotenv from 'dotenv';
import mongoose from 'mongoose';
import Subscription from '../models/Subscription';

dotenv.config();

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

        const subscriptions = await Subscription.find({});
        console.log(`Found ${subscriptions.length} total subscriptions`);

        for (const sub of subscriptions) {
            const duration = new Date(sub.endDate).getTime() - new Date(sub.startDate).getTime();
            const days = duration / (1000 * 60 * 60 * 24);
            // const planName = (sub.planId as any)?.title || 'Unknown Plan';

            console.log(`Sub ID: ${sub._id}`);
            console.log(`  User ID: ${sub.userId}`);
            console.log(`  Plan ID: ${sub.planId}`);
            console.log(`  Start: ${sub.startDate}`);
            console.log(`  End:   ${sub.endDate}`);
            console.log(`  Duration: ${days.toFixed(2)} days`);
            console.log('---');
        }

        process.exit(0);
    } catch (error) {
        console.error(error);
        process.exit(1);
    }
};

checkSubs();
