import { createShade } from '@shade/sdk';
import { loadConfig } from '../config.js';

export async function publishCommand(): Promise<void> {
  const config = loadConfig();
  console.log(`Publishing bundle to ${config.prekeyServer}...`);

  const shade = await createShade({
    prekeyServer: config.prekeyServer,
    storage: config.storage,
    address: config.address,
    autoReplenish: false,
  });

  try {
    // createShade's initialize already registers the bundle — if it got here
    // without throwing, it worked.
    console.log(`✓ Registered as "${shade.myAddress}"`);
    console.log(`  Fingerprint: ${await shade.fingerprint}`);
  } finally {
    await shade.shutdown();
  }
}
