import { describe, expect, test } from "bun:test";
import { v } from "@wrnexus/validation";
import type { InferInput, ProcedureDef, ServiceContract } from "../src/types.ts";

describe("rpc types", () => {
  test("InferInput extracts the validated shape from a schema", () => {
    // Prefixed with _ : used only via `typeof`, and the lint config requires
    // that prefix for a binding that is never read at runtime.
    const _schema = v.object({ userId: v.string(), amountCents: v.number() });
    // Compile-time assertion: assigning a correctly-shaped value must typecheck.
    const value: InferInput<typeof _schema> = { userId: "u1", amountCents: 10 };
    expect(value.userId).toBe("u1");
  });

  test("a contract carries its procedure map", () => {
    const contract: ServiceContract<{ ping: ProcedureDef }> = {
      name: "demo",
      procedures: { ping: {} },
    };
    expect(contract.name).toBe("demo");
    expect(Object.keys(contract.procedures)).toEqual(["ping"]);
  });
});
