"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const querystring = require("querystring");
const index = require("./user-v6mfWQ2d.cjs");
const getAppKeysFromSlug = require("./getAppKeysFromSlug-W8EkKxxV.cjs");
const encodeOAuthState = require("./encodeOAuthState-VBfelnxQ.cjs");
async function handler(req, res) {
  let clientId = "";
  const appKeys = await getAppKeysFromSlug.getAppKeysFromSlug("zohocrm");
  if (typeof appKeys.client_id === "string")
    clientId = appKeys.client_id;
  if (!clientId)
    return res.status(400).json({ message: "zohocrm client id missing." });
  const state = encodeOAuthState.encodeOAuthState(req);
  const params = {
    client_id: clientId,
    response_type: "code",
    redirect_uri: `${index.WEBAPP_URL}/api/integrations/zohocrm/callback`,
    scope: ["ZohoCRM.modules.ALL", "ZohoCRM.users.READ", "AaaServer.profile.READ"],
    access_type: "offline",
    state,
    prompt: "consent"
  };
  const query = querystring.stringify(params);
  const url = `https://accounts.zoho.com/oauth/v2/auth?${query}`;
  res.status(200).json({ url });
}
exports.default = handler;
