"""
Configuration file for Cognitive Prism Automation Tests
"""
import os
from pathlib import Path
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Base paths
BASE_DIR = Path(__file__).parent.parent
REPORTS_DIR = BASE_DIR / "reports"
LOGS_DIR = BASE_DIR / "logs"
DOWNLOADS_DIR = BASE_DIR / "downloads"

# Create directories if they don't exist
REPORTS_DIR.mkdir(exist_ok=True)
LOGS_DIR.mkdir(exist_ok=True)
DOWNLOADS_DIR.mkdir(exist_ok=True)

# Environment Configuration
# DEFAULT: LOCAL (as per requirements - we'll switch to live only after local automation is complete)
ENVIRONMENT = os.getenv("ENVIRONMENT", "local").lower()  # "live" or "local"

# Base URLs for different environments
LIVE_BASE_URL = "https://cognitiveprism.tech4bizsolutions.com"
LOCAL_BASE_URL = os.getenv("LOCAL_BASE_URL", "http://localhost:3983")  # Local URL (default port 3983)

# Select base URL based on environment
if ENVIRONMENT == "local":
    BASE_URL = LOCAL_BASE_URL
    print(f"🌐 Using LOCAL environment: {BASE_URL}")
else:
    BASE_URL = LIVE_BASE_URL
    print(f"🌐 Using LIVE environment: {BASE_URL}")

# Application URLs (dynamic based on environment)
LOGIN_URL = f"{BASE_URL}/"
DASHBOARD_URL = f"{BASE_URL}/student/dashboard"
ASSESSMENTS_URL = f"{BASE_URL}/assessments"
PROFILE_EDITOR_URL = f"{BASE_URL}/student/profile-builder"

# Test Credentials (Local)
# Updated from Excel: students_with_passwords_2025-12-08T08-04-09.xlsx
# Current test student: BAR210A010D (Hridaan Kade, Age: 16)
TEST_USERNAME = os.getenv("TEST_USERNAME", "SC309TB0284")  # Current test student
TEST_PASSWORD = os.getenv("TEST_PASSWORD", "VXa$Ai5kj4rV")  # Password from Excel
TEST_NEW_PASSWORD = os.getenv("TEST_NEW_PASSWORD", "Admin@123")  # Standardized new password for all students

# Student Data File
# CSV/Excel file containing student creation records
# Used to get correct DOB/age that matches school records (prevents age verification modal)
STUDENT_DATA_FILE = os.getenv("STUDENT_DATA_FILE", None)  # Auto-detects latest CSV if None

# Browser Configuration
BROWSER = os.getenv("BROWSER", "chrome").lower()
HEADLESS = os.getenv("HEADLESS", "false").lower() == "true"
IMPLICIT_WAIT = int(os.getenv("IMPLICIT_WAIT", "5"))  # Reduced from 10 - use explicit waits instead
EXPLICIT_WAIT = int(os.getenv("EXPLICIT_WAIT", "15"))  # Reduced from 30 - faster execution
PAGE_LOAD_TIMEOUT = int(os.getenv("PAGE_LOAD_TIMEOUT", "30"))  # Reduced from 60 - faster page loads
SHORT_WAIT = int(os.getenv("SHORT_WAIT", "3"))  # For quick element checks
MEDIUM_WAIT = int(os.getenv("MEDIUM_WAIT", "8"))  # For moderate waits

# Test Configuration
SCREENSHOT_ON_FAILURE = os.getenv("SCREENSHOT_ON_FAILURE", "true").lower() == "true"
SCREENSHOT_DIR = REPORTS_DIR / "screenshots"
SCREENSHOT_DIR.mkdir(exist_ok=True)

# Download Configuration
DOWNLOAD_DIR = str(DOWNLOADS_DIR)
DOWNLOAD_TIMEOUT = int(os.getenv("DOWNLOAD_TIMEOUT", "30"))

# Test Data
TEST_DATA_DIR = BASE_DIR / "test_data"

# Logging Configuration
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
LOG_FILE = LOGS_DIR / "test_execution.log"

