// 数据库清理 helper
const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

async function cleanDatabase() {
  await prisma.order.deleteMany();
  await prisma.role.deleteMany();
  await prisma.user.deleteMany();
}

async function seedExistingUser() {
  const bcrypt = require('bcryptjs');
  const testData = require('./test-data');
  await prisma.user.create({
    data: {
      account: testData.users.existing.account,
      password: bcrypt.hashSync(testData.users.existing.password, 10),
      isCreator: true,
      creatorName: testData.users.existing.account,
      libraryName: 'E2E测试库',
    },
  });
}

async function disconnect() {
  await prisma.$disconnect();
}

module.exports = { cleanDatabase, seedExistingUser, disconnect, prisma };
