#!/usr/bin/env node
require('dotenv').config();
const { getDb } = require('../src/utils/db.util');

(async () => {
  const db = await getDb();
  const collection = db.collection('documents');

  // Get all archived, confidential, and internal documents
  const docs = await collection.find({
    visibility: { $in: ['archived', 'confidential', 'internal'] }
  }).project({ slug: 1, title: 1, visibility: 1 }).sort({ visibility: 1, slug: 1 }).toArray();

  console.log('\n📋 Documents with visibility: archived, confidential, internal\n');

  const byVisibility = {
    archived: [],
    confidential: [],
    internal: []
  };

  docs.forEach(doc => {
    byVisibility[doc.visibility] = byVisibility[doc.visibility] || [];
    byVisibility[doc.visibility].push(doc);
  });

  Object.entries(byVisibility).forEach(([visibility, documents]) => {
    if (documents.length > 0) {
      console.log(`\n${visibility.toUpperCase()} (${documents.length}):`);
      documents.forEach(doc => {
        console.log(`  - ${doc.slug}`);
      });
    }
  });

  console.log(`\n\nTotal: ${docs.length} documents\n`);
  process.exit(0);
})();
