#!/usr/bin/env python3
"""Classify unrated drafts using Ollama two-stage filter."""

import sqlite3
import sys
sys.path.insert(0, "src")

from ietf_analyzer.classifier import Classifier
from ietf_analyzer.config import Config

cfg = Config.load()
conn = sqlite3.connect(cfg.db_path)
conn.row_factory = sqlite3.Row

# Get unrated drafts
rows = conn.execute("""
    SELECT name, title, abstract, source FROM drafts
    WHERE name NOT IN (SELECT draft_name FROM ratings)
    ORDER BY source, name
""").fetchall()

drafts = [dict(r) for r in rows]
print(f"Classifying {len(drafts)} unrated drafts...\n")

with Classifier(cfg) as clf:
    relevant, irrelevant = clf.classify_batch(drafts, verbose=True)

print(f"\n--- RELEVANT ({len(relevant)}) ---")
for d in relevant:
    print(f"  [{d['source']}] {d['name']}")
    print(f"    {d['title'][:100]}")

print(f"\n--- IRRELEVANT ({len(irrelevant)}) ---")
for d in irrelevant:
    print(f"  [{d['source']}] {d['name']}")
    print(f"    {d['title'][:100]}")

print(f"\nSummary: {len(relevant)} relevant, {len(irrelevant)} irrelevant out of {len(drafts)}")
conn.close()
