#!/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")

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

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


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