import re

PLACEHOLDER_PATTERNS = [
    r'^\{?\s*\}?$',
    r'^\[.*\]$',
    r'^Q?\d{1,3}\.?$',
    r'^A\d{1,3}\.?$',
    r'^(TBD|N/A|NA|NULL|NONE|TODO|XXX)$',
]

def check_question(question_text, model_answer):
    issues = []
    text = (question_text or '').strip()
    answer = (model_answer or '').strip()

    if not text or len(text) < 10:
        issues.append({'field': 'question_text', 'reason': 'missing_or_too_short'})
    elif text.endswith('...') or '???' in text:
        issues.append({'field': 'question_text', 'reason': 'truncated'})

    if not answer or len(answer) < 5 or "No model answer provided" in answer:
        issues.append({'field': 'model_answer', 'reason': 'missing_or_garbage'})

    for field, val in (('question_text', text), ('model_answer', answer)):
        if val:
            for pat in PLACEHOLDER_PATTERNS:
                if re.match(pat, val, re.IGNORECASE):
                    issues.append({'field': field, 'reason': 'placeholder'})
                    break

    return {
        'is_valid': len(issues) == 0,
        'issues': issues
    }
