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: Register,Artist,Album,Song,Stanza
const parser = fs.createReadStream(`prisma/lyrics.csv`).pipe(parse());
for await (const record of parser) {
  console.log(record[4]);
  await prisma.stanza.create({
    data: {
      text: record[4],
      register: record[0],
      song: {
        connectOrCreate: {
          where: {
            name: record[3],
          },
          create: {
            name: record[3],
            artist: {
              connectOrCreate: {
                where: {
                  name: record[1],
                },
                create: {
                  name: record[1],
                },
              },
            },
          },
        },
      },
    },
  });
}
