import { httpJson } from "@/lib/api/http" import { isApiError } from "@/lib/errors" import type { User, UserRole } from "@/lib/types" export type UpdateCurrentUserInput = { nickname?: string avatar?: string bio?: string } export async function getUserById(userId: string): Promise { try { return await httpJson(`/api/v1/users/${encodeURIComponent(userId)}`) } catch (err) { if (isApiError(err) && err.code === 404) return undefined throw err } } export async function getCurrentUserForLogin(): Promise { return httpJson("/api/v1/users/me") } export async function updateCurrentUser(input: UpdateCurrentUserInput): Promise { return httpJson("/api/v1/users/me", { method: "PUT", json: input, }) } export async function switchCurrentRole(role: UserRole): Promise { await httpJson("/api/v1/users/me/switch-role", { method: "POST", json: { role }, }) }