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

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 ItemId = string & { readonly __brand: "items.ItemId" };

export const ItemId = {
  of(value: string): Result<ItemId, ValidationError> {
    return Ok(value as ItemId);
  },
  unsafe(value: string): ItemId {
    return value as ItemId;
  },
};

export interface UpdateItem {
  readonly name: string;
}

export const UpdateItem = {
};

export interface ItemView {
  readonly id: string;
  readonly name: string;
}

export const ItemView = {
};

export const api = {
  async http_PUT_items_Param_id(id: ItemId, body: UpdateItem, deps: {}): Promise<HttpResult<ItemView>> {
    return HttpResult.Ok({ id: (id as string), name: body.name });
  },
};

export function serialise_ItemId(value: ItemId): JsonValue {
  return value as unknown as string;
}

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

export function serialise_ItemView(value: ItemView): JsonValue {
  return {
    id: value.id as JsonValue,
    name: value.name as JsonValue,
  };
}

export function deserialise_ItemView(json: JsonValue, path: string = "$"): Result<ItemView, 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 (typeof obj["id"] !== "string") {
    return Err({ kind: "StructuralMismatch", path: `${path}.id`, expected: "string", actual: typeof obj["id"] });
  }
  const __id = obj["id"];
  if (typeof obj["name"] !== "string") {
    return Err({ kind: "StructuralMismatch", path: `${path}.name`, expected: "string", actual: typeof obj["name"] });
  }
  const __name = obj["name"];
  return Ok({ id: __id, name: __name } as ItemView);
}

export function serialise_UpdateItem(value: UpdateItem): JsonValue {
  return {
    name: value.name as JsonValue,
  };
}

export function deserialise_UpdateItem(json: JsonValue, path: string = "$"): Result<UpdateItem, 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 (typeof obj["name"] !== "string") {
    return Err({ kind: "StructuralMismatch", path: `${path}.name`, expected: "string", actual: typeof obj["name"] });
  }
  const __name = obj["name"];
  return Ok({ name: __name } as UpdateItem);
}


