import os
import sys
from pathlib import Path
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

class NativeConfig:
    """
    Centralized Configuration for Antigravity Native Architecture (2026).
    """
    
    # Engine - Gemini 3 Flash for Agent Vision & Auto Browse
    MODEL_ID = "gemini-3-flash"
    
    # Paths
    ROOT_DIR = Path(__file__).parent.parent
    RULES_DIR = ROOT_DIR / ".agent" / "rules"
    APP_DATA_DIR = Path(os.getenv("APPDATA")) / ".gemini" / "antigravity"
    
    # Credentials
    _api_key = os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY")
    
    @classmethod
    def get_api_key(cls) -> str:
        if cls._api_key:
            return cls._api_key
            
        # Fallback to credential file if not in env
        cred_path = cls.ROOT_DIR / "Credentials" / "GoogleAIStudio-Gemini-AgileAdapt-API-KEY.txt"
        if cred_path.exists():
            content = cred_path.read_text().strip()
            if "=" in content:
                return content.split("=", 1)[1].strip()
            return content
        return ""

    @classmethod
    def validate(cls):
        if not cls.get_api_key():
            raise ValueError("CRITICAL: No API Key found for Gemini.")
            
config = NativeConfig()
