//#region src/media-shared/http/resolve-provider-http-request-config.ts
function resolveProviderHttpRequestConfig(options) {
	const provider = readProviderEntry(options.cfg, options.providerId);
	const request = readRequestEntry(provider);
	const timeoutMs = pickPositiveInt(request?.timeoutMs) ?? pickPositiveInt(provider?.timeoutMs) ?? pickPositiveInt(options.fallbackTimeoutMs);
	const headers = {};
	for (const src of [
		options.fallbackHeaders,
		provider?.headers,
		request?.headers
	]) {
		if (!src) continue;
		for (const [k, v] of Object.entries(src)) if (typeof v === "string" && v.length > 0) headers[k] = v;
	}
	return {
		timeoutMs,
		headers
	};
}
function readProviderEntry(cfg, id) {
	const providers = cfg?.providers;
	if (!providers || typeof providers !== "object") return void 0;
	const entry = providers[id];
	if (!entry || typeof entry !== "object") return void 0;
	return entry;
}
function readRequestEntry(provider) {
	if (!provider) return void 0;
	const request = provider.request;
	if (!request || typeof request !== "object") return void 0;
	return request;
}
function pickPositiveInt(v) {
	if (typeof v !== "number" || !Number.isFinite(v) || v <= 0) return void 0;
	return Math.floor(v);
}
//#endregion
export { resolveProviderHttpRequestConfig };

//# sourceMappingURL=resolve-provider-http-request-config.js.map