from typing import Dict, List

class RiskScorer:
    def __init__(self):
        self.cvss_weight = 0.6
        self.exploitability_weight = 0.4

    def calculate_risk_score(self, cve_data: Dict) -> float:
        cvss_score = self._get_cvss_score(cve_data)
        exploitability_score = self._get_exploitability_score(cve_data)
        
        risk_score = (cvss_score * self.cvss_weight) + (exploitability_score * self.exploitability_weight)
        return round(risk_score, 2)

    def _get_cvss_score(self, cve_data: Dict) -> float:
        impact = cve_data.get('impact', {})
        base_metric_v3 = impact.get('baseMetricV3', {})
        cvss_v3 = base_metric_v3.get('cvssV3', {})
        base_score = cvss_v3.get('baseScore', 0)
        return float(base_score)

    def _get_exploitability_score(self, cve_data: Dict) -> float:
        impact = cve_data.get('impact', {})
        base_metric_v3 = impact.get('baseMetricV3', {})
        cvss_v3 = base_metric_v3.get('cvssV3', {})
        exploitability_score = cvss_v3.get('exploitabilityScore', 0)
        return float(exploitability_score)

    def prioritize_vulnerabilities(self, vulnerabilities: List[Dict]) -> List[Dict]:
        scored_vulnerabilities = []
        for vuln in vulnerabilities:
            risk_score = self.calculate_risk_score(vuln)
            scored_vulnerabilities.append({**vuln, 'risk_score': risk_score})
        
        return sorted(scored_vulnerabilities, key=lambda x: x['risk_score'], reverse=True)
