"""
Constants and Enums for Storm Logger MCP Server - AI-Agent-Friendly Edition

This module provides all constants, enums, and magic values used throughout
the MCP server, following S-tier Python best practices:
- All magic values are named constants
- Enums for all categorical values
- Clear, descriptive names
- Comprehensive documentation
"""

from enum import Enum, auto
from pathlib import Path
from typing import Final


# ============================================================================
# Project Paths - No more hardcoded paths!
# ============================================================================

DEFAULT_PROJECT_PATH: Final[Path] = Path("/home/mathew/python-3.10.12-Projects/storm_logger")
DEFAULT_TEST_PATH: Final[str] = "tests"
DEFAULT_COVERAGE_FILE: Final[str] = ".coverage"
COVERAGE_REPORT_DIR: Final[str] = "htmlcov"


# ============================================================================
# Coverage Thresholds and Targets
# ============================================================================

class CoverageThreshold(Enum):
    """Coverage threshold levels for enterprise-grade code."""
    CRITICAL = 70.0  # Below this is unacceptable
    MINIMUM = 80.0   # Minimum acceptable coverage
    GOOD = 90.0      # Good coverage for most projects
    EXCELLENT = 95.0 # Excellent coverage
    PERFECT = 100.0  # The ultimate goal


# Default coverage settings
DEFAULT_COVERAGE_THRESHOLD: Final[float] = CoverageThreshold.GOOD.value
BUSINESS_CRITICAL_THRESHOLD: Final[float] = CoverageThreshold.EXCELLENT.value


# ============================================================================
# Test Configuration
# ============================================================================

class TestMarker(Enum):
    """Standard pytest markers for Storm Logger tests."""
    UNIT = "unit"
    INTEGRATION = "integration"
    FUNCTIONAL = "functional"
    PERFORMANCE = "performance"
    SLOW = "slow"
    DJANGO = "django"
    SECURITY = "security"
    SMOKE = "smoke"
    REGRESSION = "regression"
    NIGHTLY = "nightly"


class TestStrategy(Enum):
    """Test generation strategies."""
    MINIMAL = "minimal"          # Basic happy path tests
    STANDARD = "standard"        # Standard test coverage
    COMPREHENSIVE = "comprehensive"  # All edge cases
    ENTERPRISE = "enterprise"    # Enterprise-grade with business logic


# ============================================================================
# File and Module Patterns
# ============================================================================

PYTHON_FILE_EXTENSIONS: Final[tuple[str, ...]] = (".py", ".pyx", ".pyi")
TEST_FILE_PATTERNS: Final[tuple[str, ...]] = ("test_*.py", "*_test.py", "*_tests.py")
IGNORE_DIRECTORIES: Final[tuple[str, ...]] = (
    "__pycache__", ".git", ".venv", "venv", 
    "env", ".tox", "build", "dist", ".eggs"
)


# ============================================================================
# Business Metrics Constants
# ============================================================================

class BusinessModule(Enum):
    """Business-critical modules in Storm Logger."""
    BUSINESS_METRICS = "storm_logger.utils.business_metrics"
    PROFESSIONAL_LOGGER = "storm_logger.professional_logger"
    SANITIZER = "storm_logger.utils.sanitizer"
    MESSAGE_FORMATTER = "storm_logger.core.formatters.message_formatter"
    CONTEXT_DETECTOR = "storm_logger.context_detector"
    

class RevenueImpact(Enum):
    """Revenue impact levels for coverage gaps."""
    CRITICAL = "critical"    # Direct revenue impact
    HIGH = "high"           # Significant business impact
    MEDIUM = "medium"       # Moderate impact
    LOW = "low"            # Minimal impact


# ============================================================================
# Error Messages and Response Templates
# ============================================================================

class ErrorMessage(Enum):
    """Standard error messages for consistent communication."""
    PROJECT_NOT_FOUND = "Project path not found: {path}"
    MODULE_NOT_FOUND = "Module not found: {module}"
    TEST_NOT_FOUND = "Test file not found: {file}"
    COVERAGE_FAILED = "Coverage analysis failed: {error}"
    INVALID_PARAMETER = "Invalid parameter: {param}"
    PERMISSION_DENIED = "Permission denied: {path}"
    CONFIGURATION_ERROR = "Configuration error: {error}"


# ============================================================================
# Timeouts and Performance
# ============================================================================

DEFAULT_TIMEOUT_SECONDS: Final[int] = 300  # 5 minutes
PYTEST_TIMEOUT_SECONDS: Final[int] = 600  # 10 minutes for test runs
PARALLEL_WORKERS: Final[str] = "auto"     # For pytest-xdist

# Performance targets (from Storm Logger's 6M logs/sec capability)
PERFORMANCE_LOG_RATE: Final[int] = 6_000_000  # logs per second
PERFORMANCE_BATCH_SIZE: Final[int] = 10_000   # logs per batch


# ============================================================================
# GitLab CI/CD Constants
# ============================================================================

class GitLabStage(Enum):
    """GitLab CI/CD pipeline stages."""
    VALIDATE = ".pre"
    BUILD = "build"
    TEST = "test"
    SECURITY = "security"
    QUALITY = "quality"
    DEPLOY = "deploy"
    MONITOR = ".post"


class DeploymentEnvironment(Enum):
    """Deployment environment types."""
    DEVELOPMENT = "development"
    STAGING = "staging"
    PRODUCTION = "production"
    ENTERPRISE = "enterprise"


# ============================================================================
# Security and Compliance
# ============================================================================

class ComplianceFramework(Enum):
    """Compliance frameworks supported."""
    GDPR = "gdpr"
    HIPAA = "hipaa"
    SOC2 = "soc2"
    PCI_DSS = "pci_dss"
    ISO27001 = "iso27001"


class SecurityLevel(Enum):
    """Security scanning levels."""
    BASIC = "basic"
    STANDARD = "standard"
    ENHANCED = "enhanced"
    ENTERPRISE = "enterprise"


# ============================================================================
# MCP Tool Response Settings
# ============================================================================

MAX_RESPONSE_LENGTH: Final[int] = 32_000  # Maximum characters in response
MAX_EXAMPLES_PER_TOOL: Final[int] = 5     # Maximum examples to show
MAX_NEXT_STEPS: Final[int] = 5            # Maximum next steps to suggest
MAX_RELATED_TOOLS: Final[int] = 5         # Maximum related tools to suggest


# ============================================================================
# Pattern Matching Constants (for escaping regex hell)
# ============================================================================

class PatternPriority(Enum):
    """Priority levels for pattern matchers."""
    CRITICAL = 1    # Must process first (security)
    HIGH = 2        # Important patterns
    MEDIUM = 3      # Standard patterns
    LOW = 4         # Optional patterns


# Common replacement patterns
REDACTED_PATTERN: Final[str] = "[REDACTED]"
MASKED_PATTERN: Final[str] = "****"
SANITIZED_PATTERN: Final[str] = "[SANITIZED]"


# ============================================================================
# Development Workflow Constants
# ============================================================================

class WorkflowPhase(Enum):
    """Development workflow phases."""
    PLANNING = "planning"
    IMPLEMENTATION = "implementation"
    TESTING = "testing"
    REVIEW = "review"
    DEPLOYMENT = "deployment"
    MONITORING = "monitoring"


class TeamSize(Enum):
    """Team size categories for planning."""
    SOLO = 1
    SMALL = 5
    MEDIUM = 10
    LARGE = 20
    ENTERPRISE = 50


# ============================================================================
# Quality Metrics
# ============================================================================

class QualityMetric(Enum):
    """Code quality metrics."""
    COMPLEXITY = "complexity"
    MAINTAINABILITY = "maintainability"
    COVERAGE = "coverage"
    DOCUMENTATION = "documentation"
    TYPE_SAFETY = "type_safety"
    PERFORMANCE = "performance"


# Metric thresholds
COMPLEXITY_THRESHOLD: Final[int] = 10  # McCabe complexity
MAINTAINABILITY_INDEX_MIN: Final[float] = 20.0
DOCUMENTATION_COVERAGE_MIN: Final[float] = 80.0
TYPE_HINT_COVERAGE_MIN: Final[float] = 90.0