import { z } from 'zod';
import { publicProcedure, router } from '../trpc';
import { CreateUser, GetUserProfile } from '@crafted/domain';
import { prisma } from '@crafted/database';
import { PrismaUserRepository } from '@crafted/infrastructure';

const userRepository = new PrismaUserRepository(prisma);

export const userRouter = router({
  create: publicProcedure
    .input(z.object({ id: z.string(), email: z.string(), name: z.string() }))
    .mutation(async ({ input }) => {
      const useCase = new CreateUser(userRepository);
      return useCase.execute(input);
    }),

  me: publicProcedure
    .input(z.object({ userId: z.string() }))
    .query(async ({ input }) => {
      const useCase = new GetUserProfile(userRepository);
      return useCase.execute(input);
    }),
});
