// Generated by bynkc — do not edit by hand.
// context net.probe

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "../runtime.js";

import { Method, Request } from "../bynk.js";

import * as bynk from "../bynk.js";

export const probe = {
  async call(url: string, deps: { Fetch: bynk.Fetch; Secrets: bynk.Secrets }): Promise<number> {
    const auth = await deps.Secrets.get("PROBE_TOKEN");
    const req = { method: Method.Get, url: url, contentType: None, authorization: auth, body: None };
    const res = await deps.Fetch.send(req);
    switch (res.tag) {
      case "Ok": {
        const r = res.value;
        return r.status;
      }
      case "Err": {
        return 0;
      }
    }
    throw new Error("non-exhaustive match");
  },
};

export interface NetProbeDeps {
  readonly Fetch: bynk.Fetch;
  readonly Secrets: bynk.Secrets;
}

export function makeSurface(deps: NetProbeDeps) {
  return {
    async probe(url: string): Promise<number> {
      return probe.call(url, deps);
    },
  };
}

