import { formatResponse } from "../utils/responseData.mjs";
import { ErrorHandler } from "../utils/errors/ErrorHandler.mjs";
import { Request, Response } from "oauth2-server";

//#region src/controllers/oAuth2.controller.ts
const getOAuth2AccessToken = async (request, reply) => {
	const oauthRequest = new Request({
		headers: request.headers,
		method: request.method,
		query: request.query,
		body: request.body
	});
	const oauthResponse = new Response(reply.raw);
	try {
		const responseData = formatResponse({ data: await request.oauth.token(oauthRequest, oauthResponse) });
		return reply.send(responseData);
	} catch (error) {
		return ErrorHandler.handleAppErrorResponse(reply, error);
	}
};

//#endregion
export { getOAuth2AccessToken };
//# sourceMappingURL=oAuth2.controller.mjs.map