require('dotenv').config();

async function reloadWhitelistCommand(serverIdentifier) {
  const endpoint = `${process.env.PANEL_URL}/api/client/servers/${serverIdentifier}/command`;
  const res = await fetch(endpoint, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.PANEL_CLIENT_KEY}`,
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    },
    body: JSON.stringify({ command: "whitelist reload" })
  });

  if (res.status === 412) return true;
  if (!res.ok) throw new Error(`Command failed: ${res.statusText}`);
  return true;
}

module.exports = { reloadWhitelistCommand };
