# app/modules/prospecting/models/tech_profile.py
"""
Technology profile for a prospect's website.

Stores CMS, server, framework, analytics, and other
technology detection results from website scanning.
"""

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

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


class ProspectTechProfile(Base, TimestampMixin):
    """Technology profile detected from a prospect's website."""

    __tablename__ = "prospect_tech_profiles"

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

    # CMS Detection
    cms = Column(String(100), nullable=True)
    cms_version = Column(String(50), nullable=True)

    # Server
    server = Column(String(100), nullable=True)
    server_version = Column(String(50), nullable=True)
    hosting_provider = Column(String(100), nullable=True)
    cdn = Column(String(100), nullable=True)

    # SSL
    has_valid_cert = Column(Boolean, nullable=True)
    cert_issuer = Column(String(200), nullable=True)
    cert_expires_at = Column(DateTime, nullable=True)

    # Frontend
    js_framework = Column(String(100), nullable=True)
    analytics = Column(String(200), nullable=True)
    tag_manager = Column(String(100), nullable=True)
    ecommerce_platform = Column(String(100), nullable=True)

    # Raw data
    tech_stack_json = Column(Text, nullable=True)  # JSON string
    scan_source = Column(String(50), nullable=True)
    scan_error = Column(Text, nullable=True)

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