import { PrismaClient } from "../generated/client.ts";

const prisma = new PrismaClient();

const customers = [
  { id:  -1, name: "Max",     balance: 100 },
  { id:  -2, name: "Susi",    balance: 300 },
  { id:  -3, name: "Fritz",   balance: 500 },
  { id:  -4, name: "Andrea",  balance: 150 },
  { id:  -5, name: "Thomas",  balance: 200 },
  { id:  -6, name: "Verena",  balance: 400 },
  { id:  -7, name: "Marion",  balance: 500 },
  { id:  -8, name: "Karl",    balance: 700 },
  { id:  -9, name: "Hans",    balance: 800 },
  { id: -10, name: "Barbara", balance: 900 }
];

async function main() {
  console.log("Remove old testdata...");

  const result = await prisma.customer.deleteMany({
    where: {
      id: { lt: 0 },
    },
  });
  console.log(`Deleted ${result.count} customers with negative id`);

  console.log("Start seeding...");

  for (const customer of customers) {
    await prisma.customer.create({
      data: customer,
    });
    console.log(`Created customer with id: ${customer.id}`);
  }

  console.log("Seeding finished.");
}

try {
    await main();
}
catch (e) {
    console.error(e);
    Deno.exit(1);
}
finally {
    await prisma.$disconnect();
}