"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
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);
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};

// src/resources/upload/index.ts
var upload_exports = {};
__export(upload_exports, {
  createUploadResource: () => createUploadResource
});
module.exports = __toCommonJS(upload_exports);
function createUploadResource(baseUrl, headers) {
  return {
    upload(_0) {
      return __async(this, arguments, function* ({
        file,
        bucket,
        instance_id
      }) {
        var _b;
        const formData = new FormData();
        formData.append("file", file);
        formData.append("bucket", bucket);
        const queryParams = instance_id ? `?instance_id=${instance_id}` : "";
        const _a2 = headers, { "Content-Type": _ } = _a2, headersWithoutContentType = __objRest(_a2, ["Content-Type"]);
        const response = yield fetch(`${baseUrl}/upload${queryParams}`, {
          method: "POST",
          headers: headersWithoutContentType,
          body: formData
        });
        if (!response.ok) {
          const error = yield response.json();
          return {
            data: null,
            error: {
              message: (_b = error == null ? void 0 : error.message) != null ? _b : "Unknown error"
            }
          };
        }
        const data = yield response.json();
        return {
          data,
          error: null
        };
      });
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createUploadResource
});
