"""Defines the common interface for a vulnerability scanner.

--------------------------------------------------------------------------------
SPDX-FileCopyrightText: Copyright © 2024 Lockheed Martin <open.source@lmco.com>
SPDX-FileName: hopprcop/vulnerability_enhancer.py
SPDX-FileType: SOURCE
SPDX-License-Identifier: MIT
--------------------------------------------------------------------------------
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
--------------------------------------------------------------------------------
"""

from __future__ import annotations

from typing import TYPE_CHECKING

import rich


if TYPE_CHECKING:
    from hoppr import Vulnerability


class BaseEnhancer:
    """A super class that defines the expected interface for an enhancer."""

    offline_mode_supported: bool = False
    offline_mode: bool = False
    enabled: bool = False

    def __init_subclass__(cls, offline_mode_supported: bool = False) -> None:
        super().__init_subclass__()

        cls.offline_mode_supported = offline_mode_supported

    def enhance_vulnerabilities(self, vuln_list: list[Vulnerability]):
        """Get the enhancers.

        Return a list of enhancers for vulnerabilities or none if no vulnerabilities are found.
        """

    def should_activate(self) -> bool:
        """Checks if the enhancer should activate based on it's requirements."""
        activate = self.enabled

        if self.enabled and (self.offline_mode and not self.offline_mode_supported):
            activate = False
            rich.print(f"{type(self).__name__} is not activated because offline mode is not supported by this enhancer")

        return activate
