import { createProtectedRoute } from "@inkeep/agents-core/middleware";

//#region src/utils/openapiDualRoute.ts
/**
* Registers both a canonical and a legacy HTTP method for the same route handler.
* The legacy method gets `x-speakeasy-ignore: true` and a suffixed operationId,
* making it easy to track and remove legacy methods in the future.
*
* Standard CRUD routes: PATCH canonical (default), PUT legacy (suffix: `-put`)
* Upsert/set-replace routes: PUT canonical, PATCH legacy (suffix: `-patch`)
*
* @param canonical - 'patch' (default) for standard CRUD updates, 'put' for upsert/set-replace routes
*/
function openapiRegisterPutPatchRoutesForLegacy(app, config, handler, options) {
	const { operationId, canonical = "patch" } = options;
	const legacy = canonical === "patch" ? "put" : "patch";
	app.openapi(createProtectedRoute({
		...config,
		method: canonical,
		operationId
	}), handler);
	app.openapi(createProtectedRoute({
		...config,
		method: legacy,
		operationId: `${operationId}-${legacy}`,
		"x-speakeasy-ignore": true,
		hide: true
	}), handler);
}

//#endregion
export { openapiRegisterPutPatchRoutesForLegacy };