const axios = require('axios');
require('dotenv').config();

const API_BASE = process.env.YGOPRO_API_BASE;

async function fetchAllSets() {
  try {
    const response = await axios.get(`${API_BASE}/cardsets.php`);
    const sets = response.data.map(s => ({
      set_name: s.set_name,
      set_code: s.set_code,
      num_of_cards: s.num_of_cards || null,
      tcg_date: s.tcg_date || null
    }));
    return sets;
  } catch (err) {
    console.error('Error fetching sets from YGOPRODeck:', err.message);
    throw err;
  }
}

module.exports = { fetchAllSets };