import prisma from '../lib/prisma.js';
import { TokenType } from '../generated/prisma/enums.js';

export async function createToken(data: {
  id: string;
  token: string;
  type: TokenType;
  userId: string;
  expiresAt: Date;
}) {
  return prisma.tokens.create({ data });
}

export async function findToken(token: string) {
  return prisma.tokens.findUnique({ where: { token } });
}

export async function deleteToken(token: string) {
  return prisma.tokens.delete({ where: { token } });
}

export async function deleteTokensByUserId(userId: string) {
  return prisma.tokens.deleteMany({ where: { userId } });
}