"""企业工商信息查询模块"""
import requests
from typing import Dict, Any


class BusinessQuery:
    """企业工商信息查询类"""
    
    def __init__(self, api_key: str):
        self.api_key = api_key
        self.base_url = "https://openapi.chinaz.net/v1/1035/business4get"
    
    def query_business_info(self, keyword: str) -> Dict[str, Any]:
        """
        查询企业工商信息
        
        Args:
            keyword: 企业名称关键词
            
        Returns:
            包含企业工商信息的字典
        """
        params = {
            "APIKey": self.api_key,
            "ChinazVer": "1.0",
            "keyword": keyword
        }
        
        try:
            response = requests.get(self.base_url, params=params, timeout=60)
            result = response.json()
            
            return {
                "status_code": response.status_code,
                "success": response.status_code == 200,
                "data": result
            }
        except requests.exceptions.Timeout:
            return {
                "status_code": 0,
                "success": False,
                "error": "请求超时"
            }
        except requests.exceptions.RequestException as e:
            return {
                "status_code": 0,
                "success": False,
                "error": f"请求异常: {str(e)}"
            }
        except Exception as e:
            return {
                "status_code": 0,
                "success": False,
                "error": f"系统异常: {str(e)}"
            }
