"""Module contains class for storing information about CVEs from vendor Oracle."""

from cve_connector.vendor_cve.implementation.vendors_storage_structures.general_vendor import Vendor

from cve_connector.vendor_cve.implementation.utilities.check_correctness import is_correct_cve_id


class Oracle(Vendor):
    """
    Class for storing information about CVEs from vendor Oracle.
    """
    def __init__(self, cve='', component='', protocol='', pp_req='', remote_expl='',
                 sup_versions_aff='', product='', subcomp='', published=None):
        super().__init__()
        self.cve_id = cve
        self.component = component
        self.protocol = protocol
        self.package_privilege_req = pp_req
        self.remote_exploit_without_auth = remote_expl
        self.description = ''

        self.cvss_v3 = None
        self.cvss_v2 = None

        self.supported_versions_affected = sup_versions_aff
        self.product = product
        self.subcomponent = subcomp
        self.published = published

        self.patch_available = True

    def is_valid_entity(self):
        """
        Tests correctness of created instance of this class.

        :return: True if valid
        """
        return is_correct_cve_id(self.cve_id) \
            and self.is_valid_cvss_v3() \
            and self.is_valid_cvss_v2()

    def is_valid_cvss_v2(self):
        """
        Tests correctness of CVSS of version 2 assigned to the instance of this class.

        :return: True if valid CVSSv2
        """
        if self.cvss_v2 is None:
            return True
        return self.cvss_v2.is_valid()

    def is_valid_cvss_v3(self):
        """
        Tests correctness of CVSS of version 2 assigned to the instance of this class.

        :return: True if valid CVSSv2
        """
        if self.cvss_v3 is None:
            return True
        return self.cvss_v3.is_valid()
