import { config } from 'dotenv';
import { resolve } from 'path';
config({ path: resolve('/opt/stacks/pulse/.env.local') });

import { getDattoRMMClient } from '../lib/services/datto-rmm-factory';

async function main() {
  const client = getDattoRMMClient();
  const sites = await client.getSites();

  console.log(`Found ${sites.length} sites\n`);
  console.log('NAME\tUID\tDEVICES\tON-DEMAND');
  for (const s of sites.sort((a, b) => a.name.localeCompare(b.name))) {
    const devs = s.devicesStatus?.numberOfDevices ?? '';
    console.log(`${s.name}\t${s.uid}\t${devs}\t${s.onDemand}`);
  }
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});
