/**
 * Extract source-relevant overrides from ResolvedConfig.
 *
 * Used by orchestration steps and command handlers to call loadSource()
 * with typed overrides instead of relying on process.env.
 */
export function configToSourceOverrides(config) {
    // The explicit `--url` flag (captured in `urls`) wins over a repo-config
    // `source.baseUrl` (captured in `baseUrlOverride`); both feed the same
    // `SourceOverrides.baseUrl` the doc fetcher reads.
    const baseUrl = config.urls?.[0] ?? config.baseUrlOverride;
    return {
        ...(config.allowedOrigins?.length
            ? { allowedOrigins: config.allowedOrigins }
            : {}),
        ...(baseUrl ? { baseUrl } : {}),
        ...(config.datasetOverride ? { dataset: config.datasetOverride } : {}),
        ...(config.sanityDocumentArgs?.length
            ? { documentIds: config.sanityDocumentArgs }
            : {}),
        ...(config.headers ? { headers: config.headers } : {}),
        ...(config.perspectiveOverride
            ? { perspective: config.perspectiveOverride }
            : {}),
        ...(config.projectIdOverride
            ? { projectId: config.projectIdOverride }
            : {}),
        ...(config.studioOriginOverride
            ? { studioOrigin: config.studioOriginOverride }
            : {}),
    };
}
