"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/domain/delegates/rangr/submit.ts
var submit_exports = {};
__export(submit_exports, {
  submitRangrRfp: () => submitRangrRfp
});
module.exports = __toCommonJS(submit_exports);

// src/utils/uuid.ts
function uuidv4() {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
    const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
    return v.toString(16);
  });
}

// src/domain/delegates/rangr/submit.ts
async function submitRangrRfp(rfp, machineExecutionId, client) {
  console.log(`upsertRfpRequest machineExecutionId: ${machineExecutionId}`);
  const token = await client.auth.signIn();
  const apiKey = token.access_token;
  const url = `${client.url}/api/v2/ontologies/${client.ontologyRid}/actions/submit-rfp-request/apply`;
  const headers = {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  };
  const body = JSON.stringify({
    parameters: {
      message: rfp,
      machineExecutionId
    },
    options: {
      returnEdits: "ALL"
    }
  });
  const apiResult = await fetch(url, {
    method: "POST",
    headers,
    body
  });
  const result = await apiResult.json();
  const message = JSON.stringify(result);
  return {
    // TODO replace with status and message from service
    status: 200,
    message,
    // TODO figure out a better way to manage vendorName and ID
    vendorName: "RANGR",
    vendorId: "rangrdata.com",
    received: false,
    // TODO add executionId to context
    machineExecutionId,
    // TODO replace with reciept from service
    receipt: {
      id: uuidv4(),
      timestamp: /* @__PURE__ */ new Date()
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  submitRangrRfp
});
