"""
Inference Configuration Constants

Centralized configuration values for the inference pipeline.
Extracted from hardcoded values across multiple modules for easier maintenance.
"""

# ============================================================================
# Detection & Model Configuration
# ============================================================================

# YOLO Detection
DEFAULT_CONFIDENCE_THRESHOLD = 0.5  # Default confidence threshold for YOLO detection
DEFAULT_IOU_THRESHOLD = 0.45  # Default IoU threshold for NMS (Non-Maximum Suppression)

# ============================================================================
# Image Processing Configuration
# ============================================================================

# DPI (Dots Per Inch) for PDF rendering
DEFAULT_DPI = 300  # Standard DPI for PDF to image conversion
DPI_TO_POINTS_SCALE = 72  # PDF points per inch (used for bbox conversion)

# ============================================================================
# Customer Number Parser Configuration
# ============================================================================

# Pattern confidence scores (higher = more confident)
CUSTOMER_NUMBER_CONFIDENCE = {
    'labeled': 0.98,      # Explicit label (e.g., "Kundnummer: ABC 123-X")
    'dash_format': 0.95,  # Standard format with dash (e.g., "JTY 576-3")
    'no_dash': 0.90,      # Format without dash (e.g., "Dwq 211X")
    'compact': 0.75,      # Compact format (e.g., "JTY5763")
    'generic_base': 0.5,  # Base score for generic alphanumeric pattern
}

# Bonus scores for generic pattern matching
CUSTOMER_NUMBER_BONUS = {
    'has_dash': 0.2,      # Bonus if contains dash
    'typical_format': 0.25,  # Bonus for format XXX NNN-X
    'medium_length': 0.1,  # Bonus for length 6-12 characters
}

# Customer number length constraints
CUSTOMER_NUMBER_LENGTH = {
    'min': 6,  # Minimum length for medium length bonus
    'max': 12,  # Maximum length for medium length bonus
}

# ============================================================================
# Field Extraction Confidence Scores
# ============================================================================

# Confidence multipliers and base scores
FIELD_CONFIDENCE = {
    'pdf_text': 1.0,          # PDF text extraction (always accurate)
    'payment_line_high': 0.95,  # Payment line parsed successfully
    'regex_fallback': 0.5,    # Regex-based fallback extraction
    'ocr_penalty': 0.5,       # Penalty multiplier when OCR fails
}

# ============================================================================
# Payment Line Validation
# ============================================================================

# Account number length thresholds for type detection
ACCOUNT_TYPE_THRESHOLD = {
    'bankgiro_min_length': 7,  # Minimum digits for Bankgiro (7-8 digits)
    'plusgiro_max_length': 6,  # Maximum digits for Plusgiro (typically fewer)
}

# ============================================================================
# OCR Configuration
# ============================================================================

# Minimum OCR reference number length
MIN_OCR_LENGTH = 5  # Minimum length for valid OCR number

# ============================================================================
# Pattern Matching
# ============================================================================

# Swedish postal code pattern (to exclude from customer numbers)
SWEDISH_POSTAL_CODE_PATTERN = r'^SE\s+\d{3}\s*\d{2}'

# ============================================================================
# Usage Notes
# ============================================================================
"""
These constants can be overridden at runtime by passing parameters to
constructors or methods. The values here serve as sensible defaults
based on Swedish invoice processing requirements.

Example:
    from backend.pipeline.constants import DEFAULT_CONFIDENCE_THRESHOLD

    detector = YOLODetector(
        model_path="model.pt",
        confidence_threshold=DEFAULT_CONFIDENCE_THRESHOLD  # or custom value
    )
"""
