# classifiers.py
from openai import OpenAI
client = OpenAI()

PM_SCOPE_SYSTEM = """\
You are a strict binary classifier for PROJECT MANAGEMENT (PM) relevance.

Answer ONLY "YES" or "NO".

Return "YES" if the user input is clearly about:
- Project planning, scheduling, milestones, roadmaps
- PM frameworks & methods (Scrum, Kanban, PRINCE2, PMBOK, SAFe, OKRs)
- Scope, requirements, backlog, WBS, change requests
- Resources, roles, capacity, staffing, team coordination
- Risk, issue, dependency management
- Budgeting, cost control, business case, benefits tracking
- Stakeholder mgmt, communication, reporting, governance, PMO
- Quality mgmt, acceptance criteria, DoD, reviews, retros
- Vendor mgmt, contracts, procurement, RFP/RFQ, SLAs
- Tools for PM usage (Jira/Monday/Trello/MS Project/Asana/etc.) in a PM context

Return "NO" if the input is about:
- Pure coding help or debugging (without PM angle)
- General HR/legal/accounting without PM context
- Random trivia, personal advice, unrelated tech support
- Sales/marketing unrelated to project delivery governance
- Medical/health/personal life topics

Borderline: Require an explicit PM angle (planning, risks, stakeholders, delivery). If unsure, answer "NO".
"""

def is_pm_relevant(user_text: str) -> bool:
    resp = client.chat.completions.create(
        model="gpt-4o-mini",
        temperature=0,
        max_tokens=3,
        messages=[
            {"role": "system", "content": PM_SCOPE_SYSTEM},
            {"role": "user", "content": user_text.strip()},
        ],
    )
    ans = (resp.choices[0].message.content or "").strip().upper()
    return ans.startswith("Y")