import os
from pathlib import Path
from dotenv import load_dotenv

# Load environment variables from .env file if it exists
env_path = Path(__file__).parent.parent / '.env.production'
if env_path.exists():
    load_dotenv(env_path)
else:
    # Fallback to .env.local for development
    env_path = Path(__file__).parent.parent / '.env.local'
    if env_path.exists():
        load_dotenv(env_path)

# Get API token with validation
APIFY_API_TOKEN = os.environ.get('APIFY_API_TOKEN')

def is_facebook_scraping_enabled():
    """Check if Facebook scraping is enabled"""
    return bool(APIFY_API_TOKEN)

def validate_config():
    """Validate configuration and provide helpful error messages"""
    if not APIFY_API_TOKEN:
        return False, (
            "APIFY_API_TOKEN environment variable is not set. "
            "Facebook page scraping will be disabled. "
            "To enable this feature, set APIFY_API_TOKEN in your environment or .env file."
        )
    return True, "Configuration valid"

# Export for use in other modules
__all__ = ['APIFY_API_TOKEN', 'is_facebook_scraping_enabled', 'validate_config'] 