"""
硅基流动 (SiliconFlow) 提供商适配器

兼容 OpenAI API，继承 OpenAI 适配器
"""
import logging
from typing import List, Dict, Any

from .openai_provider import OpenAIProvider
from .registry import ProviderRegistry

logger = logging.getLogger(__name__)


@ProviderRegistry.register
class SiliconFlowProvider(OpenAIProvider):
    """
    硅基流动 (SiliconFlow) 提供商适配器
    
    兼容 OpenAI API 格式，支持多种开源模型、Embedding 和 Rerank
    """
    
    provider_type = 'siliconflow'
    provider_name = 'SiliconFlow'
    supported_model_types = ['chat', 'embedding', 'rerank']
    
    DEFAULT_API_BASE = 'https://api.siliconflow.cn/v1'
    
    @classmethod
    def get_default_models(cls) -> List[Dict[str, Any]]:
        """获取默认模型列表"""
        return [
            # ---- Chat 模型 ----
            {
                'model_name': 'Qwen/Qwen3-235B-A22B',
                'display_name': 'Qwen3 235B-A22B',
                'model_type': 'chat',
                'max_tokens': 8192,
                'context_window': 131072,
                'supports_vision': False,
                'supports_function_call': True,
                'input_price': 0.004,
                'output_price': 0.012,
            },
            {
                'model_name': 'Qwen/Qwen3-32B',
                'display_name': 'Qwen3 32B',
                'model_type': 'chat',
                'max_tokens': 8192,
                'context_window': 131072,
                'supports_vision': False,
                'supports_function_call': True,
                'input_price': 0.002,
                'output_price': 0.006,
            },
            {
                'model_name': 'Qwen/Qwen3-8B',
                'display_name': 'Qwen3 8B',
                'model_type': 'chat',
                'max_tokens': 8192,
                'context_window': 131072,
                'supports_vision': False,
                'supports_function_call': True,
                'input_price': 0,
                'output_price': 0,
            },
            {
                'model_name': 'deepseek-ai/DeepSeek-V3',
                'display_name': 'DeepSeek V3',
                'model_type': 'chat',
                'max_tokens': 8192,
                'context_window': 65536,
                'supports_vision': False,
                'supports_function_call': True,
                'input_price': 0.002,
                'output_price': 0.008,
            },
            {
                'model_name': 'deepseek-ai/DeepSeek-R1',
                'display_name': 'DeepSeek R1',
                'model_type': 'chat',
                'max_tokens': 8192,
                'context_window': 65536,
                'supports_vision': False,
                'supports_function_call': False,
                'input_price': 0.004,
                'output_price': 0.016,
            },
            {
                'model_name': 'Pro/deepseek-ai/DeepSeek-R1',
                'display_name': 'DeepSeek R1 (Pro)',
                'model_type': 'chat',
                'max_tokens': 8192,
                'context_window': 65536,
                'supports_vision': False,
                'supports_function_call': False,
                'input_price': 0.008,
                'output_price': 0.032,
            },
            # ---- Embedding 模型 ----
            {
                'model_name': 'BAAI/bge-m3',
                'display_name': 'BGE-M3',
                'model_type': 'embedding',
                'max_tokens': 8192,
                'context_window': 8192,
                'input_price': 0,
                'output_price': 0,
            },
            {
                'model_name': 'BAAI/bge-large-zh-v1.5',
                'display_name': 'BGE Large ZH v1.5',
                'model_type': 'embedding',
                'max_tokens': 512,
                'context_window': 512,
                'input_price': 0,
                'output_price': 0,
            },
            {
                'model_name': 'jinaai/jina-embeddings-v3',
                'display_name': 'Jina Embeddings V3',
                'model_type': 'embedding',
                'max_tokens': 8192,
                'context_window': 8192,
                'input_price': 0,
                'output_price': 0,
            },
            # ---- Rerank 模型 ----
            {
                'model_name': 'BAAI/bge-reranker-v2-m3',
                'display_name': 'BGE Reranker V2 M3',
                'model_type': 'rerank',
                'max_tokens': 8192,
                'context_window': 8192,
                'input_price': 0,
                'output_price': 0,
            },
            {
                'model_name': 'jinaai/jina-reranker-v2-base-multilingual',
                'display_name': 'Jina Reranker V2 Multilingual',
                'model_type': 'rerank',
                'max_tokens': 8192,
                'context_window': 8192,
                'input_price': 0,
                'output_price': 0,
            },
        ]
