// Generated by bynkc — do not edit by hand.
// context cache.secured

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

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

export const vault = {
  async call(key: string, deps: { Kv: bynk_cloudflare.Kv; Secrets: bynk.Secrets }): Promise<Option<string>> {
    const fallback = await deps.Secrets.get("CACHE_FALLBACK");
    const hit = await deps.Kv.get(key);
    switch (hit.tag) {
      case "Some": {
        const v = hit.value;
        return Some(v);
      }
      case "None": {
        return fallback;
      }
    }
    throw new Error("non-exhaustive match");
  },
};

export interface CacheSecuredDeps {
  readonly Kv: bynk_cloudflare.Kv;
  readonly Secrets: bynk.Secrets;
}

export function makeSurface(deps: CacheSecuredDeps) {
  return {
    async vault(key: string): Promise<Option<string>> {
      return vault.call(key, deps);
    },
  };
}

