import os

from pydantic import Field
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """配置"""

    # 节点信息
    NODE_VERSION: str = Field(default="", description="节点版本")
    PLATFORM_TAG: str = Field(default="", description="平台标签")

    # 端点连接配置
    ENDPOINT_URL: str = Field(description="计算端点连接地址")
    ENDPOINT_ACCESS_ID: str = Field(description="计算端点访问ID")
    ENDPOINT_ACCESS_TOKEN: str = Field(description="计算端点访问令牌")
    PING_INTERVAL: int = Field(default=5, description="心跳间隔时间(秒)")

    # 计算配置
    CPU_RESOURCE: int = Field(
        default_factory=lambda: os.cpu_count() or 1, description="CPU资源"
    )
    POLARS_MAX_THREADS: int = Field(default=1, description="Polars计算最大线程")

    # 数据同步配置
    DATA_SYNC_LOCAL_DATA_DIR: str = Field(
        default="./data", description="数据同步本地数据目录"
    )
    # 数据同步COS配置
    DATA_SYNC_COS_REGION: str = Field(default="ap-shanghai", description="COS区域")
    DATA_SYNC_COS_SECRET_ID: str = Field(default="", description="COS Secret ID")
    DATA_SYNC_COS_SECRET_KEY: str = Field(default="", description="COS Secret Key")
    DATA_SYNC_COS_BUCKET: str = Field(default="", description="COS Bucket")
    # 结果数据COS配置
    RESULT_COS_REGION: str = Field(default="ap-shanghai", description="COS区域")
    RESULT_COS_SECRET_ID: str = Field(default="", description="COS Secret ID")
    RESULT_COS_SECRET_KEY: str = Field(default="", description="COS Secret Key")
    RESULT_COS_BUCKET: str = Field(default="", description="COS Bucket")

    # Clickhouse配置
    CLICKHOUSE_URI: str = Field(default="", description="Clickhouse连接URI")

    # 实时行情 S3 共享读取配置（配置后节点直接从 S3 读取，不再本地计算）
    CB_QUOTATION_S3_URI: str = Field(default="", description="转债实时行情 S3 URI（空=本地计算）")
    STK_QUOTATION_S3_URI: str = Field(default="", description="股票实时行情 S3 URI（空=本地计算）")
    ETF_QUOTATION_S3_URI: str = Field(default="", description="ETF 实时行情 S3 URI（空=本地计算）")
    QUOTATION_S3_KEY_ID: str = Field(default="", description="行情 S3 Access Key ID")
    QUOTATION_S3_SECRET_KEY: str = Field(default="", description="行情 S3 Secret Access Key")
    QUOTATION_S3_ENDPOINT_URL: str = Field(default="", description="行情 S3 Endpoint URL（私有部署时需填）")

    class Config:
        """Pydantic config for settings."""

        env_file = ".env"
        env_file_encoding = "utf-8"
        case_sensitive = True
        extra = "allow"
