from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel

from py_ocsf_models.objects.affected_software_package import AffectedSoftwarePackage
from py_ocsf_models.objects.cve import CVE
from py_ocsf_models.objects.cwe import CWE
from py_ocsf_models.objects.remediation import Remediation


class VulnerabilityDetails(BaseModel):
    """
    The vulnerability is an unintended characteristic of a computing component or system configuration that multiplies the risk of an adverse event or a loss occurring either due to accidental exposure, deliberate attack, or conflict with new system components.

    Attributes:
    - Affected Code (affected_code) [Optional]: List of AffectedCode objects that describe details about code blocks identified as vulnerable.
    - Affected Software Packages (affected_packages) [Optional]: List of software packages identified as affected by a vulnerability/vulnerabilities.
    - CVE (cve) [Recommended]: The Common Vulnerabilities and Exposures (CVE).
    - CWE (cwe) [Recommended]: The CWE object represents a weakness in a software system that can be exploited by a threat actor to perform an attack.
    - Description (desc) [Optional]: The description of the vulnerability.
    - Exploit Availability (is_exploit_available) [Optional]: Indicates if an exploit or a PoC (proof-of-concept) is available for the reported vulnerability.
    - First Seen (first_seen_time) [Optional]: The time when the vulnerability was first observed.
    - First Seen (first_seen_time_dt) [Optional]: The time when the vulnerability was first observed in datetime format.
    - Knowledgebase Articles (kb_article_list) [Optional]: A list of KB articles or patches related to an endpoint. A KB Article contains metadata that describes the patch or an update.
    - Last Seen (last_seen_time) [Optional]: The time when the vulnerability was most recently observed.
    - Last Seen (last_seen_time_dt) [Optional]: The time when the vulnerability was most recently observed in datetime format.
    - References (references) [Recommended]: A list of reference URLs with additional information about the vulnerability.
    - Related Vulnerabilities (related_vulnerabilities) [Optional]: List of vulnerabilities that are related to this vulnerability.
    - Remediation Guidance (remediation) [Optional]: The remediation recommendations on how to mitigate the identified vulnerability.
    - Severity (severity) [Optional]: The vendor assigned severity of the vulnerability.
    - Title (title) [Optional]: A title or a brief phrase summarizing the discovered vulnerability.
    - Vendor Name (vendor_name) [Optional]: The name of the vendor that identified the vulnerability.

    Just one of these mutually exclusive attributes must be present: advisory, cve, cwe

    """

    # TODO
    # advisory: Optional[Advisory]
    # affected_code: Optional[List[AffectedCode]]
    affected_packages: Optional[List[AffectedSoftwarePackage]] = None
    cve: Optional[CVE] = None
    cwe: Optional[CWE] = None
    desc: Optional[str] = None
    is_exploit_available: Optional[bool] = None
    first_seen_time: Optional[int] = None
    first_seen_time_dt: Optional[datetime] = None
    last_seen_time: Optional[int] = None
    last_seen_time_dt: Optional[datetime] = None
    references: Optional[List[str]] = None
    related_vulnerabilities: Optional[List[str]] = None
    remediation: Optional[Remediation] = None
    severity: Optional[str] = None
    title: Optional[str] = None
    vendor_name: Optional[str] = None
