"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/contacts/search.ts
var search_exports = {};
__export(search_exports, {
  searchContacts: () => searchContacts
});
module.exports = __toCommonJS(search_exports);
async function searchContacts(fullName, company, client, pageSize = 10) {
  console.log(`searchContacts fullName: ${fullName} company: ${company}`);
  const token = await client.auth.signIn();
  const apiKey = token.access_token;
  const headers = {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  };
  const url = `${client.url}/api/v2/ontologies/${client.ontologyRid}/objects/Contacts/search`;
  const body = JSON.stringify({
    pageSize,
    where: {
      type: "and",
      value: [
        {
          type: "containsAnyTerm",
          field: "fullName",
          value: fullName,
          "fuzzy": true
        },
        {
          type: "containsAnyTerm",
          field: "company",
          value: company,
          "fuzzy": true
        }
      ]
    }
  });
  const apiResult = await fetch(url, {
    method: "POST",
    headers,
    body
  });
  const apiResponse = await apiResult.json();
  if (apiResponse.errorCode) {
    console.log(`errorInstanceId: ${apiResponse.errorCode} errorName: ${apiResponse.errorName} errorCode: ${apiResponse.errorCode}`);
    throw new Error(`An error occurred while calling search Contacts errorInstanceId: ${apiResponse.errorInstanceId} errorCode: ${apiResponse.errorCode}`);
  }
  console.log(`the Contacts ontology returned: ${JSON.stringify(apiResponse)}`);
  return apiResponse.data;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  searchContacts
});
