const require_constants = require('./constants-DJrjLmh5.cjs');
const require_url_utils = require('./url-utils-Bn5EoScr.cjs');
const require_permissions = require('./permissions-CpuEzSxz.cjs');

//#region src/cli/resolve.ts
function formatInvalid(invalid, envName) {
	const where = envName ? `${envName} provided` : "Invalid scopes provided";
	return `Error: ${where}: ${invalid.join(", ")}\nAvailable scopes: ${require_permissions.ALL_SCOPES.join(", ")}`;
}
function finalize(input) {
	if (!input.accessToken) throw new Error("Error: No access token was provided. Pass one with `--access-token` or via `SENTRY_ACCESS_TOKEN`.");
	let sentryHost = "sentry.io";
	if (input.url) sentryHost = require_url_utils.validateAndParseSentryUrlThrows(input.url);
	else if (input.host) {
		require_url_utils.validateSentryHostThrows(input.host);
		sentryHost = input.host;
	}
	let finalScopes = void 0;
	if (input.allScopes) finalScopes = new Set(require_permissions.ALL_SCOPES);
	else if (input.scopes || input.addScopes) {
		if (input.scopes) {
			const { valid, invalid } = require_permissions.parseScopes(input.scopes);
			if (invalid.length > 0) throw new Error(formatInvalid(invalid));
			if (valid.size === 0) throw new Error("Error: Invalid scopes provided. No valid scopes found.");
			finalScopes = require_permissions.resolveScopes({
				override: valid,
				defaults: require_constants.DEFAULT_SCOPES
			});
		} else if (input.addScopes) {
			const { valid, invalid } = require_permissions.parseScopes(input.addScopes);
			if (invalid.length > 0) throw new Error(formatInvalid(invalid));
			if (valid.size === 0) throw new Error("Error: Invalid additional scopes provided. No valid scopes found.");
			finalScopes = require_permissions.resolveScopes({
				add: valid,
				defaults: require_constants.DEFAULT_SCOPES
			});
		}
	}
	const resolvedOpenAiBaseUrl = input.openaiBaseUrl ? require_url_utils.validateOpenAiBaseUrlThrows(input.openaiBaseUrl) : void 0;
	return {
		accessToken: input.accessToken,
		sentryHost,
		mcpUrl: input.mcpUrl,
		sentryDsn: input.sentryDsn,
		openaiBaseUrl: resolvedOpenAiBaseUrl,
		finalScopes,
		organizationSlug: input.organizationSlug,
		projectSlug: input.projectSlug
	};
}

//#endregion
Object.defineProperty(exports, 'finalize', {
  enumerable: true,
  get: function () {
    return finalize;
  }
});
Object.defineProperty(exports, 'formatInvalid', {
  enumerable: true,
  get: function () {
    return formatInvalid;
  }
});
//# sourceMappingURL=resolve-D6Cfnjdj.cjs.map