"""
Security vulnerability model for security assessments.
"""

from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, Field, field_serializer

from omnibase_core.enums.enum_security_risk_level import EnumSecurityRiskLevel


class ModelSecurityVulnerability(BaseModel):
    """Individual security vulnerability."""

    vulnerability_id: UUID = Field(
        default=...,
        description="Vulnerability identifier (e.g., CVE-ID)",
    )
    severity: EnumSecurityRiskLevel = Field(
        default=..., description="Vulnerability severity"
    )
    description: str = Field(default=..., description="Vulnerability description")
    affected_components: list[str] = Field(
        default_factory=list,
        description="Affected components",
    )
    remediation: str | None = Field(default=None, description="Remediation steps")
    discovered_date: datetime | None = Field(
        default=None, description="When discovered"
    )
    fixed_date: datetime | None = Field(default=None, description="When fixed")

    @field_serializer("discovered_date", "fixed_date")
    def serialize_datetime(self, value: datetime | None) -> str | None:
        if value:
            return value.isoformat()
        return None
