const db = require('../config/db');

async function upsertSet(set) {
  const { set_name, set_code, num_of_cards, tcg_date } = set;

  const sql = `
    INSERT INTO sets (set_name, set_code, num_of_cards, tcg_date)
    VALUES (?, ?, ?, ?)
    ON DUPLICATE KEY UPDATE
      set_name = VALUES(set_name),
      num_of_cards = VALUES(num_of_cards),
      tcg_date = VALUES(tcg_date)
  `;
  await db.execute(sql, [set_name, set_code, num_of_cards, tcg_date]);
}

module.exports = { upsertSet };