import {
  __async,
  __esm,
  __objRest
} from "./chunk-OBKEW4AQ.mjs";

// src/resources/upload/index.ts
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
        };
      });
    }
  };
}
var init_upload = __esm({
  "src/resources/upload/index.ts"() {
  }
});

export {
  createUploadResource,
  init_upload
};
