const requiredVariables = [
  "NODE_ENV",
  "LOCATION",
  "BOT_OWNER",
  "DISCORD_GUILD_ID",
  "SHINUWA_USER_ID",
  "INVITE_LINK",
  "WEB_SERVER_PORT",
  "WEB_API_KEY",
  "DISCORD_APPLICATION_ID",
  "DISCORD_TOKEN",
  "VOICE_CHANNEL_ID",
  "TEXT_CHANNEL_ID",
  "GAME_SERVERS_MESSAGE_ID",
];

const missingVariables = requiredVariables.filter(
  (name) => !process.env[name]?.trim()
);

if (missingVariables.length > 0) {
  throw new Error(
    `Variables d'environnement manquantes : ${missingVariables.join(", ")}`
  );
}

const webServerPort = Number(process.env.WEB_SERVER_PORT);

if (!Number.isInteger(webServerPort) || webServerPort <= 0) {
  throw new Error("WEB_SERVER_PORT doit être un entier positif");
}

const config = Object.freeze({
  environnement: process.env.NODE_ENV,
  location: process.env.LOCATION,
  botOwner: process.env.BOT_OWNER,
  discordGuildId: process.env.DISCORD_GUILD_ID,
  shinuwaUserId: process.env.SHINUWA_USER_ID,
  inviteLink: process.env.INVITE_LINK,
  webServerPort,
  webApiKey: process.env.WEB_API_KEY,
  applicationId: process.env.DISCORD_APPLICATION_ID,
  token: process.env.DISCORD_TOKEN,
  voiceChannelId: process.env.VOICE_CHANNEL_ID,
  textChannelId: process.env.TEXT_CHANNEL_ID,
  gameServersMessageId: process.env.GAME_SERVERS_MESSAGE_ID,
});

export { config };
