import { getRequestFromAuthentication as p, getUrlFromServerState as s } from "@scalar/api-client";
import { getRequestFromOperation as m, getParametersFromOperation as c } from "@scalar/oas-utils/spec-getters";
import { getHarRequest as f } from "./getHarRequest.js";
function F({
  serverState: t,
  authenticationState: o,
  operation: e,
  globalSecurity: l
}) {
  var u, a;
  const r = f(
    {
      url: s(t)
    },
    m(e, { requiredOnly: !1 }),
    // Only generate authentication parameters if an authentication state is passed.
    o ? p(
      o,
      ((u = e.information) == null ? void 0 : u.security) ?? l ?? []
    ) : {}
  ), q = m(e, {
    requiredOnly: !1
  }), d = c(e, "path", !1);
  return {
    id: e.operationId,
    name: e.name,
    type: r.method,
    path: q.path ?? "",
    variables: d,
    cookies: i(r.cookies),
    query: r.queryString.map((n) => ({ ...n, enabled: n.required ?? !0 })),
    headers: i(r.headers),
    url: s(t) ?? "",
    body: (a = r.postData) == null ? void 0 : a.text
  };
}
function i(t) {
  return (t ?? []).map((o) => ({ ...o, enabled: !0 }));
}
export {
  F as getApiClientRequest
};
