"""
CVE-level remediation enrichment from external primary sources.

Separate from the per-asset Vulnerability.remediation column (the Nessus
scanner solution): these rows are keyed by cve_id and come from MSRC CVRF
(Windows + MS products) and, later, Linux distro advisories. The CVE detail
page shows them alongside the scanner remediation, grouped by source.
"""
from sqlalchemy import Column, Integer, String, Text, DateTime, func

from app.models.base import Base


class CveRemediation(Base):
    __tablename__ = "cve_remediations"

    id = Column(Integer, primary_key=True, index=True)
    cve_id = Column(String(50), nullable=False, index=True)
    source = Column(String(32), nullable=False)   # msrc | ubuntu | centos | ...
    kind = Column(String(24), nullable=False)     # fix | workaround | mitigation | advisory
    title = Column(String(300), nullable=True)
    detail = Column(Text, nullable=True)
    kb = Column(String(64), nullable=True)
    fixed_build = Column(String(120), nullable=True)
    url = Column(Text, nullable=True)
    fetched_at = Column(DateTime, nullable=False, server_default=func.now())

    def __repr__(self):
        return f"<CveRemediation(cve_id='{self.cve_id}', source='{self.source}', kind='{self.kind}')>"
