from typing import List, Dict
from .cve_data_fetcher import CVEDataFetcher

class VulnerabilityChecker:
    def __init__(self, cve_data_fetcher: CVEDataFetcher):
        self.cve_data_fetcher = cve_data_fetcher

    async def check_vulnerabilities(self, software_name: str, version: str) -> List[Dict]:
        cve_data = await self.cve_data_fetcher.fetch_cve_data()
        vulnerabilities = []

        for cve_item in cve_data:
            cve_info = cve_item['cve']
            affected_products = cve_info.get('affects', {}).get('vendor', {}).get('vendor_data', [])

            for product in affected_products:
                if product['product']['product_data'][0]['product_name'].lower() == software_name.lower():
                    for version_data in product['product']['product_data'][0]['version']['version_data']:
                        if self._version_is_vulnerable(version, version_data):
                            vulnerabilities.append({
                                'cve_id': cve_info['CVE_data_meta']['ID'],
                                'description': cve_info['description']['description_data'][0]['value'],
                                'affected_version': version_data
                            })

        return vulnerabilities

    def _version_is_vulnerable(self, current_version: str, version_data: Dict) -> bool:
        # This is a simplified version check. In a real-world scenario,
        # you'd want to implement a more robust version comparison logic.
        return current_version in version_data['version_value']
