#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
SARM SDK 漏洞 API

提供漏洞相关的API操作。
"""

from typing import List, Dict, Any, Optional, TYPE_CHECKING
from ..models.response import BatchOperationResult
from ..exceptions import SARMValidationError

if TYPE_CHECKING:
    from ..client import SARMClient


class VulnerabilityAPI:
    """漏洞API类"""
    
    def __init__(self, client: 'SARMClient'):
        self.client = client
    
    def update(self, vulnerability_data: Dict[str, Any]) -> Dict[str, Any]:
        """更新漏洞信息"""
        if 'vuln_unique_id' not in vulnerability_data:
            raise SARMValidationError("更新漏洞时必须提供 vuln_unique_id")
        
        response = self.client.post('/api/vuln/update', data=vulnerability_data)
        return response
    
    def get_list(
        self,
        page: int = 1,
        limit: int = 50,
        severity: Optional[str] = None,
        status: Optional[str] = None
    ) -> Dict[str, Any]:
        """获取漏洞列表"""
        params = {"page": page, "limit": limit}
        if severity:
            params["severity"] = severity
        if status:
            params["status"] = status
        
        response = self.client.get('/api/vuln/', params=params)
        return response 