# app/modules/prospecting/models/prospect_score.py
"""
Opportunity score for a prospect.

Scoring algorithm: 0-100 total
- Technical Health: max 40pts
- Modernity: max 25pts
- Business Value: max 25pts
- Engagement: max 10pts
"""

from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship

from app.core.database import Base
from models.database.base import TimestampMixin


class ProspectScore(Base, TimestampMixin):
    """Opportunity score computed from prospect analysis."""

    __tablename__ = "prospect_scores"

    id = Column(Integer, primary_key=True, index=True)
    prospect_id = Column(Integer, ForeignKey("prospects.id", ondelete="CASCADE"), nullable=False, unique=True)

    # Overall score
    score = Column(Integer, nullable=False, default=0, index=True)

    # Component scores
    technical_health_score = Column(Integer, nullable=False, default=0)  # max 40
    modernity_score = Column(Integer, nullable=False, default=0)  # max 25
    business_value_score = Column(Integer, nullable=False, default=0)  # max 25
    engagement_score = Column(Integer, nullable=False, default=0)  # max 10

    # Detailed breakdown
    reason_flags = Column(Text, nullable=True)  # JSON array of flag strings
    score_breakdown = Column(Text, nullable=True)  # JSON dict of flag -> points

    # Lead tier classification
    lead_tier = Column(String(20), nullable=True, index=True)  # top_priority, quick_win, strategic, low_priority

    notes = Column(Text, nullable=True)

    # Relationships
    prospect = relationship("Prospect", back_populates="score")
