import os
import typing

from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    VERSION: str = "0.1.0"
    APP_TITLE: str = "Job Data"
    PROJECT_NAME: str = "Job Data"
    APP_DESCRIPTION: str = "Job Data API"

    CORS_ORIGINS: typing.List = ["http://localhost:5173"]
    CORS_ALLOW_CREDENTIALS: bool = False
    CORS_ALLOW_METHODS: typing.List = ["GET", "POST", "PUT", "DELETE"]
    CORS_ALLOW_HEADERS: typing.List = ["*"]

    DEBUG: bool = False

    PROJECT_ROOT: str = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    BASE_DIR: str = os.path.abspath(os.path.join(PROJECT_ROOT, os.pardir))
    LOGS_ROOT: str = os.path.join(BASE_DIR, "app/logs")
    SECRET_KEY: str = "CHANGE_ME_DEV_ONLY"
    JWT_ALGORITHM: str = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7

    CLICKHOUSE_HOST: str = "121.4.126.241"
    CLICKHOUSE_PORT: int = 8123
    CLICKHOUSE_USER: str = "data_user"
    CLICKHOUSE_PASS: str = "data_pass"
    CLICKHOUSE_DB: str = "job_data"
    # Redis 用于分布式锁（可选）
    REDIS_HOST: str | None = None
    REDIS_PORT: int = 6379
    REDIS_DB: int = 0
    REDIS_PASS: str | None = None
    # 统计上报配置（可选）
    REPORT_ENDPOINT: str | None = None
    REPORT_TIMEOUT: int = 10
    REPORT_MAX_RETRIES: int = 3
    # 邮件配置（可选）
    SMTP_HOST: str | None = "smtp.qq.com"
    SMTP_PORT: int = 587
    SMTP_USER: str | None = "aa931912343@qq.com"
    SMTP_PASS: str | None = "jkncedjzkummbbdi"
    SMTP_FROM: str | None = "aa931912343@qq.com"
    SMTP_TO: list[str] = ["zfc9393@163.com"]
    # 告警窗口
    ALERT_WINDOW_MINUTES: int = 10
    TORTOISE_ORM: dict = {
        "connections": {
            "default": "mysql://root:jobdata123@121.4.126.241:3306/job_data"
        },
        "apps": {
            "models": {
                "models": ["app.models", "aerich.models", "app.models.token", "app.models.cleaning"],
                "default_connection": "default",
            },
        },
        "use_tz": False,
        "timezone": "Asia/Shanghai",
    }
    DATETIME_FORMAT: str = "%Y-%m-%d %H:%M:%S"
    RUN_MIGRATIONS_ON_STARTUP: bool = True
    INITIALIZE_SEED_DATA_ON_STARTUP: bool = True


settings = Settings()
