"""
Python coding standards and compliance data for Storm Logger development
"""

import json
from typing import Dict, Any, List


def get_python_coding_standards() -> str:
    """
    Get comprehensive Python coding standards for Storm Logger development
    
    Returns:
        JSON string with coding standards, style guides, and compliance requirements
    """
    standards = {
        "storm_logger_standards": {
            "version": "2.0.3",
            "compliance_level": "enterprise",
            "coverage_requirement": 90,
            "code_quality": {
                "formatters": {
                    "black": {
                        "line_length": 100,
                        "target_version": ["py310", "py311", "py312"],
                        "include": r"\.pyi?$",
                        "exclude": r"/(\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|venv|\.svn|_build|buck-out|build|dist)/"
                    },
                    "isort": {
                        "profile": "black",
                        "line_length": 100,
                        "multi_line_output": 3,
                        "include_trailing_comma": True,
                        "force_grid_wrap": 0,
                        "combine_as_imports": True,
                        "sections": ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
                    }
                },
                "linting": {
                    "ruff": {
                        "select": [
                            "E",   # pycodestyle errors
                            "W",   # pycodestyle warnings
                            "F",   # pyflakes
                            "I",   # isort
                            "N",   # pep8-naming
                            "D",   # pydocstyle
                            "UP",  # pyupgrade
                            "ANN", # flake8-annotations
                            "S",   # flake8-bandit
                            "B",   # flake8-bugbear
                            "A",   # flake8-builtins
                            "C4",  # flake8-comprehensions
                            "T10", # flake8-debugger
                            "T20", # flake8-print
                            "PT",  # flake8-pytest-style
                            "Q",   # flake8-quotes
                            "RET", # flake8-return
                            "SIM", # flake8-simplify
                            "TCH", # flake8-type-checking
                            "ARG", # flake8-unused-arguments
                            "PTH", # flake8-use-pathlib
                            "ERA", # eradicate
                            "PGH", # pygrep-hooks
                            "PL",  # pylint
                            "TRY", # tryceratops
                            "FLY", # flynt
                            "NPY", # numpy
                            "PERF", # perflint
                            "FURB", # refurb
                            "LOG"  # flake8-logging
                        ],
                        "ignore": [
                            "D100",  # Missing docstring in public module
                            "D104",  # Missing docstring in public package
                            "D107",  # Missing docstring in __init__
                            "ANN101", # Missing type annotation for self
                            "ANN102", # Missing type annotation for cls
                            "S101",  # Use of assert
                            "PT011", # pytest.raises too broad
                            "T201",  # print found (for debugging)
                            "T203"   # pprint found (for debugging)
                        ],
                        "line_length": 100,
                        "target_version": "py310",
                        "exclude": [
                            ".git",
                            ".hg",
                            ".mypy_cache",
                            ".nox",
                            ".tox",
                            ".venv",
                            "venv",
                            ".svn",
                            "_build",
                            "buck-out",
                            "build",
                            "dist"
                        ]
                    }
                },
                "type_checking": {
                    "mypy": {
                        "python_version": "3.10",
                        "warn_return_any": True,
                        "warn_unused_configs": True,
                        "warn_redundant_casts": True,
                        "warn_unused_ignores": True,
                        "warn_unreachable": True,
                        "check_untyped_defs": True,
                        "disallow_any_generics": True,
                        "disallow_untyped_defs": True,
                        "disallow_incomplete_defs": True,
                        "disallow_untyped_decorators": True,
                        "no_implicit_optional": True,
                        "strict_optional": True,
                        "show_error_codes": True,
                        "show_column_numbers": True,
                        "ignore_missing_imports": True
                    }
                }
            }
        },
        "naming_conventions": {
            "modules": {
                "pattern": "lowercase_with_underscores",
                "examples": ["storm_logger", "business_metrics", "test_analysis"],
                "avoid": ["CamelCase", "mixedCase", "ALLCAPS"]
            },
            "classes": {
                "pattern": "PascalCase",
                "examples": ["StormLogger", "BusinessMetrics", "TestAnalysis"],
                "avoid": ["lowercase", "snake_case", "ALLCAPS"]
            },
            "functions": {
                "pattern": "lowercase_with_underscores",
                "examples": ["analyze_code", "get_metrics", "process_data"],
                "avoid": ["CamelCase", "mixedCase", "ALLCAPS"]
            },
            "variables": {
                "pattern": "lowercase_with_underscores",
                "examples": ["user_input", "file_path", "error_count"],
                "avoid": ["CamelCase", "mixedCase", "ALLCAPS"]
            },
            "constants": {
                "pattern": "UPPERCASE_WITH_UNDERSCORES",
                "examples": ["MAX_RETRIES", "DEFAULT_TIMEOUT", "API_VERSION"],
                "avoid": ["lowercase", "CamelCase", "mixedCase"]
            },
            "private_attributes": {
                "pattern": "_single_leading_underscore",
                "examples": ["_private_method", "_internal_state", "_helper_function"],
                "avoid": ["__double_leading", "no_underscore"]
            },
            "special_methods": {
                "pattern": "__double_leading_and_trailing__",
                "examples": ["__init__", "__str__", "__repr__"],
                "note": "Only use for Python special methods"
            }
        },
        "documentation_standards": {
            "docstring_style": "google",
            "docstring_requirements": {
                "public_functions": "required",
                "public_classes": "required",
                "public_methods": "required",
                "private_functions": "recommended",
                "private_methods": "recommended",
                "modules": "required"
            },
            "docstring_format": {
                "summary": "Single line summary",
                "description": "Detailed description (optional)",
                "args": "List all parameters with types and descriptions",
                "returns": "Describe return value with type",
                "raises": "List exceptions that may be raised",
                "examples": "Provide usage examples (recommended)"
            }
        },
        "code_organization": {
            "project_structure": {
                "recommended_layout": {
                    "src/": "Source code directory",
                    "src/package_name/": "Main package directory",
                    "src/package_name/__init__.py": "Package initialization",
                    "src/package_name/core/": "Core functionality",
                    "src/package_name/utils/": "Utility functions",
                    "src/package_name/integrations/": "Framework integrations",
                    "tests/": "Test directory",
                    "tests/unit/": "Unit tests",
                    "tests/integration/": "Integration tests",
                    "tests/functional/": "Functional tests",
                    "docs/": "Documentation",
                    "scripts/": "Build and deployment scripts",
                    "pyproject.toml": "Project configuration",
                    "requirements.txt": "Dependencies",
                    "README.md": "Project documentation",
                    "CHANGELOG.md": "Version history"
                }
            }
        },
        "testing_standards": {
            "coverage_requirements": {
                "overall": 90,
                "core_modules": 95,
                "critical_paths": 100,
                "utilities": 85,
                "integrations": 80
            },
            "testing_framework": "pytest",
            "testing_practices": {
                "isolation": "Each test should be independent",
                "repeatability": "Tests should produce consistent results",
                "clarity": "Test names should clearly describe what is being tested",
                "coverage": "Aim for high code coverage with meaningful tests",
                "performance": "Include performance tests for critical operations"
            }
        },
        "security_standards": {
            "input_validation": {
                "sanitization": "Always sanitize user input",
                "validation": "Validate all input parameters",
                "type_checking": "Use type hints and runtime type checking",
                "bounds_checking": "Check array bounds and string lengths"
            },
            "data_protection": {
                "pii_handling": "Implement PII detection and removal",
                "secrets_management": "Never hardcode secrets or keys",
                "encryption": "Use encryption for sensitive data",
                "access_control": "Implement proper access controls"
            }
        },
        "performance_standards": {
            "optimization_guidelines": {
                "premature_optimization": "Don't optimize without measuring",
                "profiling": "Use profiling tools to identify bottlenecks",
                "algorithms": "Choose appropriate algorithms and data structures",
                "caching": "Implement strategic caching",
                "async_programming": "Use async/await for I/O-bound operations"
            },
            "performance_targets": {
                "response_time": "< 100ms for simple operations",
                "throughput": "> 1000 requests per second",
                "memory_usage": "< 50MB for typical operations",
                "startup_time": "< 1 second for application startup"
            }
        },
        "compliance_requirements": {
            "storm_logger_compliance": {
                "logging_integration": "Must use Storm Logger for all logging",
                "business_metrics": "Must track relevant business metrics",
                "error_handling": "Must implement comprehensive error handling",
                "configuration": "Must use Storm Logger configuration patterns"
            },
            "enterprise_requirements": {
                "reliability": "99.9% uptime requirement",
                "scalability": "Must support horizontal scaling",
                "maintainability": "Code must be maintainable by team",
                "documentation": "Comprehensive documentation required"
            }
        }
    }
    
    return json.dumps(standards, indent=2)


def get_python_best_practices() -> str:
    """
    Get Python best practices and recommendations
    
    Returns:
        JSON string with best practices organized by category
    """
    practices = {
        "general_practices": {
            "code_style": [
                "Follow PEP 8 style guide",
                "Use meaningful variable and function names",
                "Keep functions small and focused",
                "Use docstrings for all public functions and classes",
                "Prefer composition over inheritance",
                "Use type hints for better code documentation"
            ],
            "error_handling": [
                "Use specific exception types",
                "Handle exceptions at the appropriate level",
                "Use try-except-finally appropriately",
                "Don't suppress exceptions without good reason",
                "Log exceptions with appropriate context",
                "Use custom exceptions for application-specific errors"
            ],
            "performance": [
                "Use appropriate data structures",
                "Avoid premature optimization",
                "Profile before optimizing",
                "Use generators for large datasets",
                "Cache expensive computations",
                "Use async/await for I/O-bound operations"
            ]
        },
        "storm_logger_practices": {
            "logging": [
                "Use Storm Logger for all logging needs",
                "Set appropriate log levels",
                "Include context in log messages",
                "Use structured logging",
                "Implement business metrics collection",
                "Use professional console output"
            ],
            "configuration": [
                "Use Storm Logger configuration patterns",
                "Implement environment-specific configs",
                "Validate configuration at startup",
                "Use type-safe configuration classes",
                "Support runtime configuration updates"
            ],
            "testing": [
                "Use Storm Logger test fixtures",
                "Test logging behavior",
                "Test error handling paths",
                "Test configuration scenarios",
                "Achieve high test coverage"
            ]
        },
        "security_practices": [
            "Validate all user inputs",
            "Sanitize data before processing",
            "Use parameterized queries for databases",
            "Implement proper authentication and authorization",
            "Encrypt sensitive data",
            "Use secure random number generation",
            "Keep dependencies up to date",
            "Implement proper session management"
        ],
        "testing_practices": [
            "Write tests first (TDD)",
            "Keep tests independent",
            "Use descriptive test names",
            "Test edge cases and error conditions",
            "Mock external dependencies",
            "Use fixtures for test data",
            "Maintain high test coverage",
            "Run tests automatically in CI/CD"
        ],
        "deployment_practices": [
            "Use virtual environments",
            "Pin dependency versions",
            "Use configuration management",
            "Implement health checks",
            "Use monitoring and logging",
            "Implement graceful shutdowns",
            "Use container orchestration",
            "Implement blue-green deployments"
        ]
    }
    
    return json.dumps(practices, indent=2)