import os

# Shared with the rest of the app: race-api is one self-hosted gateway, so the
# base URL, key and model come from the same env vars services/ai_service.py
# already reads. No recruitment-specific secret exists.
RACE_API_BASE_URL = os.getenv("RACE_API_BASE_URL", "http://127.0.0.1:8080")
RACE_API_KEY = os.getenv("RACE_API_KEY")
RACE_API_MODEL = os.getenv("RACE_API_MODEL", "gpt-oss-120b")

# Key callers must send in the `x-api-key` header. Defaults to the race key so
# a single secret in .env is enough; set RECRUITMENT_API_KEY to use a separate one.
API_KEY = os.getenv("RECRUITMENT_API_KEY") or RACE_API_KEY

RACE_OCR_URL =f"{RACE_API_BASE_URL}/v1/ocr"
RACE_CHAT_URL = f"{RACE_API_BASE_URL}/v1/chat/completions"

# Upload limits. race-api enforces its own OCR cap too; rejecting here first
# avoids shipping a large body over the wire just to be refused.
MAX_RESUME_BYTES = int(os.getenv("RECRUITMENT_MAX_PDF_MB", "5")) * 1024 * 1024
MAX_JD_CHARS = int(os.getenv("RECRUITMENT_MAX_JD_CHARS", "10000"))

# Resume text handed to the LLM is capped so one pathological PDF cannot blow
# the context window; a real resume is a few thousand characters.
MAX_RESUME_TEXT_CHARS = int(os.getenv("RECRUITMENT_MAX_RESUME_TEXT_CHARS", "30000"))

LLM_MAX_TOKENS = int(os.getenv("RECRUITMENT_LLM_MAX_TOKENS", "4096"))

# JD generation: how many ai_interview_questions to request, scaled by the
# role's experience band so a senior role gets a deeper interview than a
# junior one. Checked in order as (years_below, question_count); the first
# band where the role's experience is strictly below years_below applies.
# 10 is a deliberate floor -- every band starts at 10, not lower.
JD_QUESTION_COUNT_BANDS = (
    (2, 10),   # 0-2 yrs
    (5, 12),   # 2-5 yrs
    (8, 14),   # 5-8 yrs
)
JD_QUESTION_COUNT_DEFAULT = 16   # 8+ yrs, past every band above
JD_QUESTION_COUNT_UNSPECIFIED = 10   # min_range/max_range absent or unparseable

# JD generation: fixed lengths for these sections, env-configurable so they
# can be tuned per deployment without a code change. required_skills is
# deliberately NOT here -- its count stays open to the model's judgment.
JD_SUMMARY_SENTENCES = int(os.getenv("RECRUITMENT_JD_SUMMARY_SENTENCES", "3"))
JD_RESPONSIBILITIES_COUNT = int(os.getenv("RECRUITMENT_JD_RESPONSIBILITIES_COUNT", "6"))
JD_QUALIFICATIONS_COUNT = int(os.getenv("RECRUITMENT_JD_QUALIFICATIONS_COUNT", "4"))
JD_PREFERRED_SKILLS_COUNT = int(os.getenv("RECRUITMENT_JD_PREFERRED_SKILLS_COUNT", "4"))

# OCR of a scanned multi-page PDF is slow; the LLM call is the other long pole.
OCR_TIMEOUT_SECONDS = float(os.getenv("RECRUITMENT_OCR_TIMEOUT_SECONDS", "120"))
LLM_TIMEOUT_SECONDS = float(os.getenv("RECRUITMENT_LLM_TIMEOUT_SECONDS", "120"))
