import { publicProcedure, router } from '../trpc';
import {
  registerUser,
  loginUser,
  logoutUser,
  getCurrentUserProfile,
  sendPasswordReset,
} from '@crafted/services';
import { registerInput, loginInput, resetPasswordInput } from '@crafted/validators';

export const authRouter = router({
  register: publicProcedure
    .input(registerInput)
    .mutation(async ({ input }) => {
      return await registerUser(input);
    }),

  login: publicProcedure
    .input(loginInput)
    .mutation(async ({ input }) => {
      return await loginUser(input);
    }),

  logout: publicProcedure.mutation(async () => {
    return await logoutUser();
  }),

  me: publicProcedure.query(async () => {
    return await getCurrentUserProfile();
  }),

  resetPassword: publicProcedure
    .input(resetPasswordInput)
    .mutation(async ({ input }) => {
      return await sendPasswordReset(input);
    }),
});
