// Generated by bynkc — do not edit by hand.
// context demo.svc

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

export type Failure =
    { readonly tag: "Down" };

export const Failure = {
  Down: { tag: "Down" } as Failure,
};

export interface Source {
  fetch(id: number): Promise<Result<number, Failure>>;
}

export const SourceToken: unique symbol = Symbol("Source");

export const totalise = {
  async call(id: number, deps: { Source: Source }): Promise<Result<number, Failure>> {
    const raw = await deps.Source.fetch(id);
    const __r0 = raw;
    if (__r0.tag === "Err") return __r0;
    const n = __r0.value;
    return Ok(n + 1);
  },
};

export interface DemoSvcDeps {
  readonly Source: Source;
}

export function makeSurface(deps: DemoSvcDeps) {
  return {
    async totalise(id: number): Promise<Result<number, Failure>> {
      return totalise.call(id, deps);
    },
  };
}

