text: require("dotenv").config();
  const {
    renderError,
    parseBoolean,
    CONSTANTS,
    isLocaleAvailable,
  } = require("../src/common/utils");
  const { fetchWakatimeStats } = require("../src/fetchers/wakatime-fetcher");
  const wakatimeCard = require("../src/cards/wakatime-card");
  
  module.exports = async (req, res) => {
    const {
      username,
      title_color,
      icon_color,
      hide_border,
      line_height,
      text_color,
      bg_color,
      theme,
      hide_title,
      hide_progress,
      custom_title,
      locale,
      layout,
      langs_count,
      api_domain,
      range,
      border_radius,
      border_color,
    } = req.query;
  
    res.setHeader("Content-Type", "image/svg+xml");
  
    if (locale && !isLocaleAvailable(locale)) {
      return res.send(renderError("Something went wrong", "Language not found"));
    }
  
    try {
      const stats = await fetchWakatimeStats({ username, api_domain, range });
  
      let cache = CONSTANTS.ONE_DAY;
      if (username === "ridays2001") cache = CONSTANTS.THIRTY_MINUTES;
      res.setHeader("Cache-Control", `public, max-age=${cache}`);
  
      return res.send(
        wakatimeCard(stats, {
          custom_title,
          hide_title: parseBoolean(hide_title),
          hide_border: parseBoolean(hide_border),
          line_height,
          title_color,
          icon_color,
          text_color,
          bg_color,
          theme,
          hide_progress,
          border_radius,
          border_color,
          locale: locale ? locale.toLowerCase() : null,
          layout,
          langs_count,
        }),
      );
    } catch (err) {
      return res.send(renderError(err.message, err.secondaryMessage));
    }
  };
  