import { InstrumentationConfig } from '@apm-js-collab/code-transformer';

interface LegacyBundlerPluginOptions {
    /**
     * Enable debug logging
     */
    debug?: boolean;
    /**
     * Additional instrumentation configs to apply
     */
    instrumentations?: InstrumentationConfig[];
    /**
     * Whether to bundle for browser environments.
     *
     * When true, uses 'dc-browser' for browser-compatible diagnostics_channel polyfill.
     * When false, uses Node.js built-in 'diagnostics_channel' and 'async_hooks'.
     * Defaults to true (assumes browser build).
     */
    browser?: boolean;
}

/**
 * Webpack loader for auto-instrumentation.
 *
 * This is a webpack loader (not a plugin) for compatibility with tools that only support loaders,
 * such as Next.js Turbopack.
 *
 * Usage in next.config.js / next.config.ts:
 * ```javascript
 * const nextConfig: NextConfig = {
 *   turbopack: {
 *     rules: {
 *       // Apply the loader to all JS/MJS/CJS files from node_modules.
 *       // condition: "foreign" restricts the rule to third-party packages only.
 *       "*.{js,mjs,cjs}": {
 *         condition: "foreign",
 *         loaders: [{ loader: require.resolve("braintrust/webpack-loader") }],
 *       },
 *     },
 *   },
 * };
 * ```
 */

/**
 * Webpack loader that instruments JavaScript code using code-transformer.
 *
 * Accepts the same options as the legacy webpack plugin.
 */
declare function codeTransformerLoader(this: any, code: string, inputSourceMap?: any): void;
declare namespace codeTransformerLoader {
    type Options = LegacyBundlerPluginOptions;
}

export { codeTransformerLoader as default };
