const require_chunk = require('./chunk-DWy1uDak.cjs');
const require_errors = require('./errors-BtJEw2Z-.cjs');
const require_define = require('./define-BfP4rFlE.cjs');
const require_logging = require('./logging-CkAJKyq2.cjs');
const require_api = require('./api-CZD9zwQ-.cjs');
const require_schema = require('./schema-Cv_VNAHz.cjs');
const __sentry_core = require_chunk.__toESM(require("@sentry/core"));
const zod = require_chunk.__toESM(require("zod"));

//#region src/tools/update-project.ts
var update_project_default = require_define.defineTool({
	name: "update_project",
	requiredScopes: ["project:write"],
	description: [
		"Update project settings in Sentry, such as name, slug, platform, and team assignment.",
		"",
		"Be careful when using this tool!",
		"",
		"Use this tool when you need to:",
		"- Update a project's name or slug to fix onboarding mistakes",
		"- Change the platform assigned to a project",
		"- Update team assignment for a project",
		"",
		"<examples>",
		"### Update a project's name and slug",
		"",
		"```",
		"update_project(organizationSlug='my-organization', projectSlug='old-project', name='New Project Name', slug='new-project-slug')",
		"```",
		"",
		"### Assign a project to a different team",
		"",
		"```",
		"update_project(organizationSlug='my-organization', projectSlug='my-project', teamSlug='backend-team')",
		"```",
		"",
		"### Update platform",
		"",
		"```",
		"update_project(organizationSlug='my-organization', projectSlug='my-project', platform='python')",
		"```",
		"",
		"</examples>",
		"",
		"<hints>",
		"- If the user passes a parameter in the form of name/otherName, it's likely in the format of <organizationSlug>/<projectSlug>.",
		"- Team assignment is handled separately from other project settings",
		"- If any parameter is ambiguous, you should clarify with the user what they meant.",
		"- When updating the slug, the project will be accessible at the new slug after the update",
		"</hints>"
	].join("\n"),
	inputSchema: {
		organizationSlug: require_schema.ParamOrganizationSlug,
		regionUrl: require_schema.ParamRegionUrl.optional(),
		projectSlug: require_schema.ParamProjectSlug,
		name: zod.z.string().trim().describe("The new name for the project").optional(),
		slug: zod.z.string().toLowerCase().trim().describe("The new slug for the project (must be unique)").optional(),
		platform: require_schema.ParamPlatform.optional(),
		teamSlug: require_schema.ParamTeamSlug.optional().describe("The team to assign this project to. Note: this will replace the current team assignment.")
	},
	annotations: {
		readOnlyHint: false,
		destructiveHint: true,
		idempotentHint: true,
		openWorldHint: true
	},
	async handler(params, context) {
		const apiService = require_api.apiServiceFromContext(context, { regionUrl: params.regionUrl });
		const organizationSlug = params.organizationSlug;
		(0, __sentry_core.setTag)("organization.slug", organizationSlug);
		(0, __sentry_core.setTag)("project.slug", params.projectSlug);
		if (params.teamSlug) {
			(0, __sentry_core.setTag)("team.slug", params.teamSlug);
			try {
				await apiService.addTeamToProject({
					organizationSlug,
					projectSlug: params.projectSlug,
					teamSlug: params.teamSlug
				});
			} catch (err) {
				require_logging.logIssue(err);
				throw new Error(`Failed to assign team ${params.teamSlug} to project ${params.projectSlug}: ${err instanceof Error ? err.message : "Unknown error"}`);
			}
		}
		const hasProjectUpdates = params.name || params.slug || params.platform;
		let project;
		if (hasProjectUpdates) try {
			project = await apiService.updateProject({
				organizationSlug,
				projectSlug: params.projectSlug,
				name: params.name,
				slug: params.slug,
				platform: params.platform
			});
		} catch (err) {
			require_logging.logIssue(err);
			throw new Error(`Failed to update project ${params.projectSlug}: ${err instanceof Error ? err.message : "Unknown error"}`);
		}
		else {
			const projects = await apiService.listProjects(organizationSlug);
			project = projects.find((p) => p.slug === params.projectSlug);
			if (!project) throw new require_errors.UserInputError(`Project ${params.projectSlug} not found`);
		}
		let output = `# Updated Project in **${organizationSlug}**\n\n`;
		output += `**ID**: ${project.id}\n`;
		output += `**Slug**: ${project.slug}\n`;
		output += `**Name**: ${project.name}\n`;
		if (project.platform) output += `**Platform**: ${project.platform}\n`;
		const updates = [];
		if (params.name) updates.push(`name to "${params.name}"`);
		if (params.slug) updates.push(`slug to "${params.slug}"`);
		if (params.platform) updates.push(`platform to "${params.platform}"`);
		if (params.teamSlug) updates.push(`team assignment to "${params.teamSlug}"`);
		if (updates.length > 0) {
			output += `\n## Updates Applied\n`;
			output += updates.map((update) => `- Updated ${update}`).join("\n");
			output += `\n`;
		}
		output += "\n# Using this information\n\n";
		output += `- The project is now accessible at slug: \`${project.slug}\`\n`;
		if (params.teamSlug) output += `- The project is now assigned to the \`${params.teamSlug}\` team\n`;
		return output;
	}
});

//#endregion
Object.defineProperty(exports, 'update_project_default', {
  enumerable: true,
  get: function () {
    return update_project_default;
  }
});
//# sourceMappingURL=update-project-DMRBdOZ5.cjs.map