import { eq } from "drizzle-orm";
import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";
import { players, type Player } from "@/server/db/schema";

export const playerRouter = createTRPCRouter({
  getBySession: publicProcedure.query(async ({ ctx }) => {
    return ctx?.session?.user
      ? ((await ctx.db.query.players.findFirst({
          where: eq(players.id, ctx.session.user.id),
        })) as Player)
      : null;
  }),
});
