import { assertObject, assertString, assertNumber } from "../../shared/src/asserts.js";
import { callDefaultFetch } from "./call-default-fetch.js";
import { assertCookie } from "./cookies.js";
import { isClientStateNotFoundResponse, isVersionNotSupportedResponse } from "./error-responses.js";
import { assertHTTPRequestInfo } from "./http-request-info.js";
import { assertPatchOperations } from "./patch-operation.js";
function getDefaultPuller(rep) {
  async function puller(requestBody, requestID) {
    const [response, httpRequestInfo] = await callDefaultFetch(
      rep.pullURL,
      rep.auth,
      requestID,
      requestBody
    );
    if (!response) {
      return { httpRequestInfo };
    }
    return {
      response: await response.json(),
      httpRequestInfo
    };
  }
  defaultPullers.add(puller);
  return puller;
}
const defaultPullers = /* @__PURE__ */ new WeakSet();
function isDefaultPuller(puller) {
  return defaultPullers.has(puller);
}
function assertPullResponseV1(v) {
  assertObject(v);
  if (isClientStateNotFoundResponse(v) || isVersionNotSupportedResponse(v)) {
    return;
  }
  if (v.cookie !== void 0) {
    assertCookie(v.cookie);
  }
  assertLastMutationIDChanges(v.lastMutationIDChanges);
  assertPatchOperations(v.patch);
}
function assertLastMutationIDChanges(lastMutationIDChanges) {
  assertObject(lastMutationIDChanges);
  for (const [key, value] of Object.entries(lastMutationIDChanges)) {
    assertString(key);
    assertNumber(value);
  }
}
function assertPullerResultV1(v) {
  assertObject(v);
  assertHTTPRequestInfo(v.httpRequestInfo);
  if (v.response !== void 0) {
    assertPullResponseV1(v.response);
  }
}
export {
  assertPullResponseV1,
  assertPullerResultV1,
  getDefaultPuller,
  isDefaultPuller
};
//# sourceMappingURL=get-default-puller.js.map
