// Generated by bynkc — do not edit by hand.
// context reaper

import { Ok, Err, Some, None, type Result, type Option, type ValidationError, type JsonValue, type BoundaryError, type ServiceBinding, callService, boundaryError } from "../../runtime.js";

export type ReaperError =
    { readonly tag: "StorageUnavailable" };

export const ReaperError = {
  StorageUnavailable: { tag: "StorageUnavailable" } as ReaperError,
};

export const sweeper = {
  async cron_sweeper_0(deps: {}): Promise<Result<void, ReaperError>> {
    return Err(ReaperError.StorageUnavailable);
  },
};

export function serialise_ReaperError(value: ReaperError): JsonValue {
  switch (value.tag) {
    case "StorageUnavailable":
      return { kind: "StorageUnavailable" };
  }
}

export function deserialise_ReaperError(json: JsonValue, path: string = "$"): Result<ReaperError, BoundaryError> {
  if (typeof json !== "object" || json === null || Array.isArray(json)) {
    return Err({ kind: "StructuralMismatch", path, expected: "object", actual: typeof json });
  }
  const obj = json as { [k: string]: JsonValue };
  const kind = obj["kind"];
  switch (kind) {
    case "StorageUnavailable":
      return Ok({ tag: "StorageUnavailable" } as ReaperError);
    default:
      return Err({ kind: "StructuralMismatch", path, expected: "sum variant kind", actual: String(kind) });
  }
}


export function serialise_Result_Unit_ReaperError(value: Result<void, ReaperError>): JsonValue {
  if (value.tag === "Ok") return { kind: "Ok", value: null };
  return { kind: "Err", error: serialise_ReaperError(value.error) };
}

export function deserialise_Result_Unit_ReaperError(json: JsonValue, path: string = "$"): Result<Result<void, ReaperError>, BoundaryError> {
  if (typeof json !== "object" || json === null || Array.isArray(json)) {
    return Err({ kind: "StructuralMismatch", path, expected: "object", actual: typeof json });
  }
  const obj = json as { [k: string]: JsonValue };
  if (obj["kind"] === "Ok") {
  const __v = undefined;
    return Ok(Ok(__v) as Result<void, ReaperError>);
  } else if (obj["kind"] === "Err") {
  const __r_e = deserialise_ReaperError(obj["error"], `${path}.error`);
  if (__r_e.tag === "Err") return __r_e;
  const __e = __r_e.value;
    return Ok(Err(__e) as Result<void, ReaperError>);
  }
  return Err({ kind: "StructuralMismatch", path, expected: "Ok | Err", actual: String(obj["kind"]) });
}

