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

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

export type UserId = string & { readonly __brand: "api.UserId" };

export const UserId = {
  of(value: string): Result<UserId, ValidationError> {
    if (!(value.length > 0)) {
      return Err({ field: "UserId", message: "must be non-empty", value });
    }
    return Ok(value as UserId);
  },
  unsafe(value: string): UserId {
    return value as UserId;
  },
};

export const api = {
  async http_GET_admin(deps: { identity: UserId }): Promise<HttpResult<UserId>> {
    return HttpResult.Ok(deps.identity);
  },
};

export function serialise_UserId(value: UserId): JsonValue {
  return value as unknown as string;
}

export function deserialise_UserId(json: JsonValue, path: string = "$"): Result<UserId, BoundaryError> {
  if (typeof json !== "string") {
    return Err({ kind: "StructuralMismatch", path, expected: "string", actual: typeof json });
  }
  const validated = (typeof (UserId as any).of === "function")
    ? (UserId as any).of(json)
    : Ok(json as unknown as UserId);
  if (validated.tag === "Err") {
    return Err({ kind: "RefinementViolation", path, violation: validated.error });
  }
  return Ok(validated.value as UserId);
}


