"""
环境变量常量定义 - 对应 packages/shared/src/env/constants.ts

定义模型配置相关的环境变量名称。
"""

# 默认模型配置键
MIDSCENE_MODEL_NAME = "MIDSCENE_MODEL_NAME"
MIDSCENE_MODEL_BASE_URL = "MIDSCENE_MODEL_BASE_URL"
MIDSCENE_MODEL_API_KEY = "MIDSCENE_MODEL_API_KEY"
MIDSCENE_MODEL_FAMILY = "MIDSCENE_MODEL_FAMILY"
MIDSCENE_MODEL_TIMEOUT = "MIDSCENE_MODEL_TIMEOUT"
MIDSCENE_MODEL_TEMPERATURE = "MIDSCENE_MODEL_TEMPERATURE"
MIDSCENE_MODEL_RETRY_COUNT = "MIDSCENE_MODEL_RETRY_COUNT"
MIDSCENE_MODEL_RETRY_INTERVAL = "MIDSCENE_MODEL_RETRY_INTERVAL"
MIDSCENE_MODEL_SOCKS_PROXY = "MIDSCENE_MODEL_SOCKS_PROXY"
MIDSCENE_MODEL_HTTP_PROXY = "MIDSCENE_MODEL_HTTP_PROXY"
MIDSCENE_MODEL_INIT_CONFIG_JSON = "MIDSCENE_MODEL_INIT_CONFIG_JSON"

# Insight 模型配置键
MIDSCENE_INSIGHT_MODEL_NAME = "MIDSCENE_INSIGHT_MODEL_NAME"
MIDSCENE_INSIGHT_MODEL_BASE_URL = "MIDSCENE_INSIGHT_MODEL_BASE_URL"
MIDSCENE_INSIGHT_MODEL_API_KEY = "MIDSCENE_INSIGHT_MODEL_API_KEY"
MIDSCENE_INSIGHT_MODEL_FAMILY = "MIDSCENE_INSIGHT_MODEL_FAMILY"
MIDSCENE_INSIGHT_MODEL_TIMEOUT = "MIDSCENE_INSIGHT_MODEL_TIMEOUT"
MIDSCENE_INSIGHT_MODEL_TEMPERATURE = "MIDSCENE_INSIGHT_MODEL_TEMPERATURE"
MIDSCENE_INSIGHT_MODEL_RETRY_COUNT = "MIDSCENE_INSIGHT_MODEL_RETRY_COUNT"
MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL = "MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL"
MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY = "MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY"
MIDSCENE_INSIGHT_MODEL_HTTP_PROXY = "MIDSCENE_INSIGHT_MODEL_HTTP_PROXY"
MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON = "MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON"

# Planning 模型配置键
MIDSCENE_PLANNING_MODEL_NAME = "MIDSCENE_PLANNING_MODEL_NAME"
MIDSCENE_PLANNING_MODEL_BASE_URL = "MIDSCENE_PLANNING_MODEL_BASE_URL"
MIDSCENE_PLANNING_MODEL_API_KEY = "MIDSCENE_PLANNING_MODEL_API_KEY"
MIDSCENE_PLANNING_MODEL_FAMILY = "MIDSCENE_PLANNING_MODEL_FAMILY"
MIDSCENE_PLANNING_MODEL_TIMEOUT = "MIDSCENE_PLANNING_MODEL_TIMEOUT"
MIDSCENE_PLANNING_MODEL_TEMPERATURE = "MIDSCENE_PLANNING_MODEL_TEMPERATURE"
MIDSCENE_PLANNING_MODEL_RETRY_COUNT = "MIDSCENE_PLANNING_MODEL_RETRY_COUNT"
MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL = "MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL"
MIDSCENE_PLANNING_MODEL_SOCKS_PROXY = "MIDSCENE_PLANNING_MODEL_SOCKS_PROXY"
MIDSCENE_PLANNING_MODEL_HTTP_PROXY = "MIDSCENE_PLANNING_MODEL_HTTP_PROXY"
MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON = "MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON"

# 兼容旧版环境变量（已废弃，仅用于向后兼容）
# @deprecated Use MIDSCENE_MODEL_API_KEY instead
OPENAI_API_KEY = "OPENAI_API_KEY"
# @deprecated Use MIDSCENE_MODEL_BASE_URL instead
OPENAI_BASE_URL = "OPENAI_BASE_URL"
MIDSCENE_OPENAI_SOCKS_PROXY = "MIDSCENE_OPENAI_SOCKS_PROXY"
MIDSCENE_OPENAI_HTTP_PROXY = "MIDSCENE_OPENAI_HTTP_PROXY"
MIDSCENE_OPENAI_INIT_CONFIG_JSON = "MIDSCENE_OPENAI_INIT_CONFIG_JSON"

# 模型家族开关（兼容旧版）
MIDSCENE_USE_DOUBAO_VISION = "MIDSCENE_USE_DOUBAO_VISION"
MIDSCENE_USE_QWEN_VL = "MIDSCENE_USE_QWEN_VL"
MIDSCENE_USE_QWEN3_VL = "MIDSCENE_USE_QWEN3_VL"
MIDSCENE_USE_VLM_UI_TARS = "MIDSCENE_USE_VLM_UI_TARS"
MIDSCENE_USE_GEMINI = "MIDSCENE_USE_GEMINI"
MIDSCENE_USE_ANTHROPIC = "MIDSCENE_USE_ANTHROPIC"

# Anthropic/Claude 模型配置键
MIDSCENE_ANTHROPIC_API_KEY = "MIDSCENE_ANTHROPIC_API_KEY"
MIDSCENE_ANTHROPIC_BASE_URL = "MIDSCENE_ANTHROPIC_BASE_URL"
MIDSCENE_ANTHROPIC_MODEL_NAME = "MIDSCENE_ANTHROPIC_MODEL_NAME"

# 有效的模型家族值
MODEL_FAMILY_VALUES = [
    "openai",
    "qwen2.5-vl",
    "qwen3-vl",
    "doubao-vision",
    "gemini",
    "claude",
    "vlm-ui-tars",
    "vlm-ui-tars-doubao",
    "vlm-ui-tars-doubao-1.5",
]

# Intent 类型
INTENT_DEFAULT = "default"
INTENT_INSIGHT = "insight"
INTENT_PLANNING = "planning"


# 配置键映射
class ModelConfigKeys:
    """模型配置键"""
    def __init__(
        self,
        model_name: str,
        openai_base_url: str,
        openai_api_key: str,
        model_family: str,
        timeout: str,
        temperature: str,
        retry_count: str,
        retry_interval: str,
        socks_proxy: str,
        http_proxy: str,
        openai_extra_config: str,
    ):
        self.model_name = model_name
        self.openai_base_url = openai_base_url
        self.openai_api_key = openai_api_key
        self.model_family = model_family
        self.timeout = timeout
        self.temperature = temperature
        self.retry_count = retry_count
        self.retry_interval = retry_interval
        self.socks_proxy = socks_proxy
        self.http_proxy = http_proxy
        self.openai_extra_config = openai_extra_config


DEFAULT_MODEL_CONFIG_KEYS = ModelConfigKeys(
    model_name=MIDSCENE_MODEL_NAME,
    openai_base_url=MIDSCENE_MODEL_BASE_URL,
    openai_api_key=MIDSCENE_MODEL_API_KEY,
    model_family=MIDSCENE_MODEL_FAMILY,
    timeout=MIDSCENE_MODEL_TIMEOUT,
    temperature=MIDSCENE_MODEL_TEMPERATURE,
    retry_count=MIDSCENE_MODEL_RETRY_COUNT,
    retry_interval=MIDSCENE_MODEL_RETRY_INTERVAL,
    socks_proxy=MIDSCENE_MODEL_SOCKS_PROXY,
    http_proxy=MIDSCENE_MODEL_HTTP_PROXY,
    openai_extra_config=MIDSCENE_MODEL_INIT_CONFIG_JSON,
)

INSIGHT_MODEL_CONFIG_KEYS = ModelConfigKeys(
    model_name=MIDSCENE_INSIGHT_MODEL_NAME,
    openai_base_url=MIDSCENE_INSIGHT_MODEL_BASE_URL,
    openai_api_key=MIDSCENE_INSIGHT_MODEL_API_KEY,
    model_family=MIDSCENE_INSIGHT_MODEL_FAMILY,
    timeout=MIDSCENE_INSIGHT_MODEL_TIMEOUT,
    temperature=MIDSCENE_INSIGHT_MODEL_TEMPERATURE,
    retry_count=MIDSCENE_INSIGHT_MODEL_RETRY_COUNT,
    retry_interval=MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL,
    socks_proxy=MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY,
    http_proxy=MIDSCENE_INSIGHT_MODEL_HTTP_PROXY,
    openai_extra_config=MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON,
)

PLANNING_MODEL_CONFIG_KEYS = ModelConfigKeys(
    model_name=MIDSCENE_PLANNING_MODEL_NAME,
    openai_base_url=MIDSCENE_PLANNING_MODEL_BASE_URL,
    openai_api_key=MIDSCENE_PLANNING_MODEL_API_KEY,
    model_family=MIDSCENE_PLANNING_MODEL_FAMILY,
    timeout=MIDSCENE_PLANNING_MODEL_TIMEOUT,
    temperature=MIDSCENE_PLANNING_MODEL_TEMPERATURE,
    retry_count=MIDSCENE_PLANNING_MODEL_RETRY_COUNT,
    retry_interval=MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL,
    socks_proxy=MIDSCENE_PLANNING_MODEL_SOCKS_PROXY,
    http_proxy=MIDSCENE_PLANNING_MODEL_HTTP_PROXY,
    openai_extra_config=MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON,
)

# 兼容旧版的配置键
DEFAULT_MODEL_CONFIG_KEYS_LEGACY = ModelConfigKeys(
    model_name=MIDSCENE_MODEL_NAME,
    openai_base_url=OPENAI_BASE_URL,
    openai_api_key=OPENAI_API_KEY,
    model_family=MIDSCENE_MODEL_FAMILY,
    timeout=MIDSCENE_MODEL_TIMEOUT,
    temperature=MIDSCENE_MODEL_TEMPERATURE,
    retry_count=MIDSCENE_MODEL_RETRY_COUNT,
    retry_interval=MIDSCENE_MODEL_RETRY_INTERVAL,
    socks_proxy=MIDSCENE_OPENAI_SOCKS_PROXY,
    http_proxy=MIDSCENE_OPENAI_HTTP_PROXY,
    openai_extra_config=MIDSCENE_OPENAI_INIT_CONFIG_JSON,
)

KEYS_MAP = {
    INTENT_DEFAULT: DEFAULT_MODEL_CONFIG_KEYS,
    INTENT_INSIGHT: INSIGHT_MODEL_CONFIG_KEYS,
    INTENT_PLANNING: PLANNING_MODEL_CONFIG_KEYS,
}


__all__ = [
    "MIDSCENE_MODEL_NAME",
    "MIDSCENE_MODEL_BASE_URL",
    "MIDSCENE_MODEL_API_KEY",
    "MIDSCENE_MODEL_FAMILY",
    "OPENAI_API_KEY",
    "OPENAI_BASE_URL",
    "MIDSCENE_ANTHROPIC_API_KEY",
    "MIDSCENE_ANTHROPIC_BASE_URL",
    "MIDSCENE_ANTHROPIC_MODEL_NAME",
    "MIDSCENE_USE_ANTHROPIC",
    "MODEL_FAMILY_VALUES",
    "INTENT_DEFAULT",
    "INTENT_INSIGHT",
    "INTENT_PLANNING",
    "ModelConfigKeys",
    "DEFAULT_MODEL_CONFIG_KEYS",
    "INSIGHT_MODEL_CONFIG_KEYS",
    "PLANNING_MODEL_CONFIG_KEYS",
    "DEFAULT_MODEL_CONFIG_KEYS_LEGACY",
    "KEYS_MAP",
]
