import { AgentIdPClient } from '@sentryagent/idp-sdk';
import { loadCredentials } from './auth';

/**
 * Returns an AgentIdPClient configured with credentials from sessionStorage.
 * Throws if not authenticated (caller must ensure login first).
 */
export function getClient(): AgentIdPClient {
  const creds = loadCredentials();
  if (!creds) {
    throw new Error('Not authenticated. Please log in.');
  }
  return new AgentIdPClient({
    baseUrl: creds.baseUrl,
    clientId: creds.clientId,
    clientSecret: creds.clientSecret,
  });
}
