import { PrismaClient } from "@prisma/client";
import fs from "node:fs";
import { parse } from "csv";

const prisma = new PrismaClient();
// lyrics from https://docs.google.com/spreadsheets/d/1b8gANkghKpJKPzsPEigggxOydGgM8ntX0EAI4rPwbSU/edit?gid=0#gid=0
// csv header: Artist,Album,Song,Stanza
const parser = fs.createReadStream(`prisma/lyrics.csv`).pipe(parse());
for await (const record of parser) {
  console.log(record[3]);
  await prisma.stanza.create({
    data: {
      text: record[3],
      register: record[4],
      song: {
        connectOrCreate: {
          where: {
            name: record[2],
          },
          create: {
            name: record[2],
            artist: {
              connectOrCreate: {
                where: {
                  name: record[0],
                },
                create: {
                  name: record[0],
                },
              },
            },
          },
        },
      },
    },
  });
}
