'use strict';

function parsePositiveInteger(value, fallback) {
  const parsed = Number(value);
  return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
}

// Gemini API rate limiting — default below the 15 RPM free-tier ceiling.
const GEMINI_RATE_DELAY_MS = parsePositiveInteger(process.env.GEMINI_RATE_DELAY_MS, 5000);
const GEMINI_RETRY_BASE_DELAY_MS = 5000;
const GEMINI_429_DELAY_MS = 30000;
const GEMINI_MAX_RETRIES = 5;
const GEMINI_MAX_OUTPUT_TOKENS = 600;

// HTTP fetch defaults
const FETCH_TIMEOUT_MS = 12_000;

// Scraper politeness delays (ms between requests to same host)
const SCRAPER_DELAY_MS = 300;
const SCRAPER_DELAY_SLOW_MS = 400; // Workable needs more time
const SCRAPER_DELAY_RSS_MS = 500;

// Content limits
const MAX_DESCRIPTION_LENGTH = 15000;

// Dashboard
const DASHBOARD_PORT = parseInt(process.env.DASHBOARD_PORT, 10) || 3131;
const DASHBOARD_HOST = process.env.DASHBOARD_HOST || 'localhost';
const DASHBOARD_BASE_URL = process.env.DASHBOARD_BASE_URL || `http://${DASHBOARD_HOST}:${DASHBOARD_PORT}`;

// Score thresholds (used across UI rendering + filters)
const SCORE_STRONG = 8;
const SCORE_GOOD = 7;
const SCORE_MID = 6;
const SCORE_BORDERLINE = 5;

// Gemini free tier daily request limit
const GEMINI_DAILY_LIMIT = 500;

const DAILY_TARGET = 5;

// Auto-ghost: applied jobs with no response after this many days get marked ghosted
const GHOSTED_AFTER_DAYS = 14;

module.exports = {
  GEMINI_RATE_DELAY_MS,
  GEMINI_RETRY_BASE_DELAY_MS,
  GEMINI_429_DELAY_MS,
  GEMINI_MAX_RETRIES,
  GEMINI_MAX_OUTPUT_TOKENS,
  FETCH_TIMEOUT_MS,
  SCRAPER_DELAY_MS,
  SCRAPER_DELAY_SLOW_MS,
  SCRAPER_DELAY_RSS_MS,
  MAX_DESCRIPTION_LENGTH,
  DASHBOARD_PORT,
  DASHBOARD_HOST,
  DASHBOARD_BASE_URL,
  SCORE_STRONG,
  SCORE_GOOD,
  SCORE_MID,
  SCORE_BORDERLINE,
  GEMINI_DAILY_LIMIT,
  DAILY_TARGET,
  GHOSTED_AFTER_DAYS,
};
