// 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 interface Profile {
  readonly id: UserId;
}

export const Profile = {
};

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

export function serialise_Profile(value: Profile): JsonValue {
  return {
    id: serialise_UserId(value.id),
  };
}

export function deserialise_Profile(json: JsonValue, path: string = "$"): Result<Profile, 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 __r_id = deserialise_UserId(obj["id"], `${path}.id`);
  if (__r_id.tag === "Err") return __r_id;
  const __id = __r_id.value;
  return Ok({ id: __id } as Profile);
}

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);
}


