import uuid
from sqlalchemy import Column, String, Boolean, DateTime, ForeignKey, func
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship

from app.database import Base


class IntelItem(Base):
    """
    Intelligence item model for tracking threat intelligence related to techniques.
    
    Stores URLs and metadata from automated intel scans that may indicate
    new attack variations or detection bypasses for specific techniques.
    """
    __tablename__ = "intel_items"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    technique_id = Column(UUID(as_uuid=True), ForeignKey("techniques.id"), nullable=True)
    url = Column(String, nullable=False)
    title = Column(String, nullable=True)
    source = Column(String, nullable=True)
    detected_at = Column(DateTime(timezone=True), server_default=func.now())
    reviewed = Column(Boolean, default=False)

    # Relationships
    technique = relationship("Technique")
