"""
Clients Package - 外部服务客户端

统一管理与外部服务的连接客户端，如 LLM、声纹识别、数据库等。
"""
# 配置项统一从 src.config 导入
from src.config import (
    # 基础配置
    SECRET_KEY,
    UPLOAD_FOLDER,
    LOG_LEVEL,
    MAX_FILE_SIZE_MB,
    # ASR 配置
    USE_ASR_ENDPOINT,
    ASR_BASE_URL,
    ASR_DIARIZE,
    ASR_MIN_SPEAKERS,
    ASR_MAX_SPEAKERS,
    # LLM 配置
    TEXT_MODEL_BASE_URL,
    TEXT_MODEL_NAME,
    TEXT_MODEL_API_KEY,
    # 音频分段配置
    ENABLE_CHUNKING,
    # Inquire 配置
    ENABLE_INQUIRE_MODE,
    MAX_TOKENS_FOR_TRANSCRIPTION,
    SPEAKR_TOKENS_FOR_TRANSCRIPTION,
    # 外部 API 配置
    TRANSCRIPTION_BASE_URL,
    VALID_TOKEN,
    # 数据库配置
    SQLALCHEMY_DATABASE_URI,
    DB_POOL_SIZE,
    DB_MAX_OVERFLOW,
    DB_POOL_TIMEOUT,
    DB_POOL_RECYCLE,
)

from .llm_client import (
    client,
    http_client_no_proxy,
)

from .voiceprint_client import (
    VoiceprintClient,
    voiceprint_client,
)

from .database import (
    db,
    init_database,
    get_database_uri,
    is_postgresql,
)

# 嵌入功能依赖检测
try:
    import numpy as np
    from sentence_transformers import SentenceTransformer
    from sklearn.metrics.pairwise import cosine_similarity
    EMBEDDINGS_AVAILABLE = True
except ImportError:
    EMBEDDINGS_AVAILABLE = False
    
    class SentenceTransformer:
        def __init__(self, *args, **kwargs):
            pass
        def encode(self, *args, **kwargs):
            return []
    
    np = None
    cosine_similarity = None

# 音频分段服务初始化
from src.services.audio_chunking import AudioChunkingService
chunking_service = AudioChunkingService() if ENABLE_CHUNKING else None

__all__ = [
    # 基础配置
    'SECRET_KEY',
    'UPLOAD_FOLDER',
    'LOG_LEVEL',
    'MAX_FILE_SIZE_MB',
    # ASR 配置
    'USE_ASR_ENDPOINT',
    'ASR_BASE_URL',
    'ASR_DIARIZE',
    'ASR_MIN_SPEAKERS',
    'ASR_MAX_SPEAKERS',
    # LLM 配置
    'TEXT_MODEL_BASE_URL',
    'TEXT_MODEL_NAME',
    'TEXT_MODEL_API_KEY',
    # 音频分段配置
    'ENABLE_CHUNKING',
    # Inquire 配置
    'ENABLE_INQUIRE_MODE',
    'MAX_TOKENS_FOR_TRANSCRIPTION',
    'SPEAKR_TOKENS_FOR_TRANSCRIPTION',
    # 外部 API 配置
    'TRANSCRIPTION_BASE_URL',
    'VALID_TOKEN',
    # 数据库配置
    'SQLALCHEMY_DATABASE_URI',
    'DB_POOL_SIZE',
    'DB_MAX_OVERFLOW',
    'DB_POOL_TIMEOUT',
    'DB_POOL_RECYCLE',
    # 客户端
    'client',
    'http_client_no_proxy',
    'VoiceprintClient',
    'voiceprint_client',
    # 数据库
    'db',
    'init_database',
    'get_database_uri',
    'is_postgresql',
    # 服务实例
    'chunking_service',
    'EMBEDDINGS_AVAILABLE',
]
