#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
模块名称：config.py
模块描述：应用配置管理

作者：czj
创建日期：2026-07-09
最后修改：2026-07-09
"""

import os
from typing import Optional


class Settings:
    """
    应用配置类

    Attributes:
        APP_NAME (str): 应用名称
        APP_VERSION (str): 应用版本
        DEBUG (bool): 是否调试模式
        DATABASE_URL (str): 数据库连接 URL
        CORS_ORIGINS (list): 允许的跨域来源
        PLAYWRIGHT_HEADLESS (bool): Playwright 是否无头模式
        SCREENSHOT_DIR (str): 截图存储目录
    """

    # 基础配置
    APP_NAME: str = "平台自动化测试系统"
    APP_VERSION: str = "1.0.0"
    DEBUG: bool = os.getenv("DEBUG", "false").lower() == "true"

    # 数据库配置
    DATABASE_URL: str = os.getenv(
        "DATABASE_URL",
        "sqlite+aiosqlite:///./data/test_platform.db"
    )

    # CORS 配置
    CORS_ORIGINS: list = ["*"]  # 生产环境应限制来源

    # Playwright 配置
    PLAYWRIGHT_HEADLESS: bool = os.getenv(
        "PLAYWRIGHT_HEADLESS",
        "true"
    ).lower() == "true"
    PLAYWRIGHT_TIMEOUT: int = int(os.getenv("PLAYWRIGHT_TIMEOUT", "30000"))

    # 文件存储配置
    SCREENSHOT_DIR: str = os.getenv("SCREENSHOT_DIR", "./data/screenshots")
    REPORT_DIR: str = os.getenv("REPORT_DIR", "./data/reports")

    # 设备模拟配置
    DEVICE_SIM_MAX_INSTANCES: int = int(os.getenv("DEVICE_SIM_MAX_INSTANCES", "50"))
    DEVICE_SIM_DEFAULT_REPORT_INTERVAL: int = int(os.getenv("DEVICE_SIM_DEFAULT_REPORT_INTERVAL", "30"))
    DEVICE_SIM_LOG_RETENTION_DAYS: int = int(os.getenv("DEVICE_SIM_LOG_RETENTION_DAYS", "7"))
    ENCRYPTION_KEY: str = os.getenv("ENCRYPTION_KEY", "")

    # 日志配置
    LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")

    # Claude 语义增强配置
    CLAUDE_ENABLED: bool = os.getenv("CLAUDE_ENABLED", "true").lower() == "true"
    CLAUDE_TIMEOUT: int = int(os.getenv("CLAUDE_TIMEOUT", "60"))  # 秒（Claude CLI 首次调用需要初始化）
    CLAUDE_MODEL: str = os.getenv("CLAUDE_MODEL", "claude-sonnet-5")  # 默认模型
    CLAUDE_MAX_CANDIDATES: int = int(os.getenv("CLAUDE_MAX_CANDIDATES", "5"))  # 最大候选数

    class Config:
        """Pydantic 配置"""
        env_file = ".env"


# 全局配置实例
settings = Settings()