const cloudinary = require('cloudinary').v2;
require('dotenv').config({ path: '.env.local' });

cloudinary.config({
  cloud_name: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
  api_key: process.env.CLOUDINARY_API_KEY,
  api_secret: process.env.CLOUDINARY_API_SECRET
});

async function listResources() {
  try {
    console.log('Fetching assets from Cloudinary...');
    let allResources = [];
    let nextCursor = null;

    do {
      const result = await cloudinary.api.resources({
        type: 'upload',
        prefix: 'salmakisyat/',
        max_results: 500,
        next_cursor: nextCursor
      });
      allResources = allResources.concat(result.resources);
      nextCursor = result.next_cursor;
    } while (nextCursor);

    const mapping = allResources.map(res => ({
      public_id: res.public_id,
      folder: res.folder
    }));

    console.log(JSON.stringify(mapping, null, 2));
  } catch (error) {
    console.error('Error fetching resources:', error);
  }
}

listResources();
