import { Ficmas } from "../models/challenges/ficmas";
import { MongoClient } from "mongodb";
import mongoose from "mongoose";
import { uri, olduri } from "../lib/dbconfig";

import { Band } from "../models/band";

const cli = new MongoClient(olduri);
export default async function () {
	try {
		await cli.connect()

		await mongoose.connect(uri).then(() => console.log("connect'd"));

		const db = cli.db("rockfic_old")
		const col = db.collection("ficmas_wishes");
		const cursor = col.find({});
		for await(const s of cursor) {
			const bandList = await Band.find({name: {$in: s.bands}})
			const f = new Ficmas({
				_id: s.wishid,
				bands: bandList.map(a => a._id),
				year: s.year,
				kink: s.kink,
				anniversary: s.isAnniversary,
				wisher: s.wisher,
				relationship: s.relationship
			})
			await f.save();
		}
	} catch(e) {
		console.error(e)
	} finally {
		return 0
	}
}
