import { defineService, implement, procedure } from "@wrnexus/rpc";
import { v } from "@wrnexus/validation";

export const greeter = defineService({
  name: "greeter",
  procedures: {
    greet: procedure
      .input(v.object({ name: v.string() }))
      .output<{ message: string; subject: string }>()
      .build(),
  },
});

export default implement(
  greeter,
  {
    greet: async ({ name }, ctx) => ({
      message: `Hello, ${name}`,
      subject: ctx.subject?.subjectId ?? "anonymous",
    }),
  },
  { selfApp: "auth-showcase" },
);
