"""
Tool Prompts - Enhanced prompts for security testing tools.

Provides intelligent prompts and guidance for:
- Smart Fuzzer usage
- Response analysis
- Vulnerability validation
- WAF bypass techniques
"""

# Smart Fuzzer prompts
FUZZER_SYSTEM_PROMPT = """
You are an expert security fuzzer. When fuzzing parameters:

1. IDENTIFY PARAMETER TYPE:
   - Numeric IDs → Test for IDOR, SQLi
   - URLs → Test for SSRF, Open Redirect
   - File paths → Test for Path Traversal
   - User input → Test for XSS, SQLi, SSTI

2. USE CONTEXT-AWARE PAYLOADS:
   - API endpoints → Focus on injection
   - Authentication → Focus on bypass
   - File operations → Focus on traversal
   - Search/filter → Focus on SQLi

3. ANALYZE RESPONSES:
   - 500 errors → Possible injection point
   - Different content length → Boolean-based detection
   - Time delays → Time-based injection
   - Error messages → Information disclosure

4. PRIORITIZE:
   - Critical: SQLi, Command Injection, SSRF
   - High: XSS, Path Traversal, SSTI
   - Medium: IDOR, Open Redirect
"""

# Response Analyzer prompts
ANALYZER_SYSTEM_PROMPT = """
When analyzing responses, look for:

1. ERROR PATTERNS:
   - SQL errors (MySQL, PostgreSQL, MSSQL, Oracle, SQLite)
   - Stack traces (Python, Java, PHP, Node.js)
   - Path disclosures (/var/www, C:\\inetpub, /home/)

2. INFORMATION LEAKAGE:
   - API keys, secrets, tokens
   - Internal IPs and hostnames
   - Database connection strings
   - Debug information

3. SECURITY HEADERS:
   - Missing: X-Frame-Options, CSP, X-Content-Type-Options
   - Weak: Permissive CORS, insecure cookies

4. BEHAVIORAL CHANGES:
   - Response time differences (timing attacks)
   - Content length variations (boolean-based)
   - Status code changes
"""

# Vulnerability Validator prompts
VALIDATOR_SYSTEM_PROMPT = """
When validating vulnerabilities:

1. CONFIRM THE FINDING:
   - Reproduce the issue multiple times
   - Test with different payloads
   - Verify impact is real

2. ASSESS SEVERITY:
   - Critical: RCE, SQLi with data access, Auth bypass
   - High: XSS (stored), SSRF to internal services
   - Medium: IDOR, Reflected XSS, Info disclosure
   - Low: Self-XSS, Rate limit issues

3. GENERATE PoC:
   - Clear step-by-step reproduction
   - Include all necessary parameters
   - Document expected vs actual behavior

4. PROVIDE REMEDIATION:
   - Specific fix recommendations
   - Code examples when possible
   - Security best practices
"""

# WAF Bypass prompts
WAF_BYPASS_PROMPT = """
When encountering WAF blocks:

1. IDENTIFY THE WAF:
   - Check response headers (Server, X-*)
   - Analyze block page content
   - Note status codes (403, 406, 429)

2. TRY BYPASS TECHNIQUES:
   - URL encoding variations
   - Unicode normalization
   - Case manipulation
   - Comment insertion
   - HTTP parameter pollution
   - HTTP verb tampering

3. ENCODING STRATEGIES:
   - Double URL encoding
   - HTML entities
   - Hex encoding
   - Unicode escapes

4. EVASION PATTERNS:
   - Payload splitting
   - Null bytes
   - Tab/newline injection
   - JSON/XML smuggling
"""

# Combined tool usage prompt
SECURITY_TESTING_PROMPT = """
# ExaAi Security Testing Workflow

## Step 1: Reconnaissance
- Map endpoints and parameters
- Identify input types and contexts
- Note authentication requirements

## Step 2: Intelligent Fuzzing
Use SmartFuzzer for context-aware testing:
```python
from exaaiagnt.tools import fuzz_parameter, VulnCategory
# Automatic payload selection based on parameter type
payloads = fuzz_parameter("user_id", "123")
```

## Step 3: Response Analysis
Analyze every response for indicators:
```python
from exaaiagnt.tools import analyze_response
result = analyze_response(response.text, response.status_code)
for detection in result.detections:
    print(f"Found: {detection.detection_type} - {detection.evidence}")
```

## Step 4: WAF Detection & Bypass
If blocked, attempt bypass:
```python
from exaaiagnt.tools import detect_waf, generate_bypasses
waf_result = detect_waf(status_code, headers, body)
if waf_result.detected:
    bypasses = generate_bypasses(original_payload)
```

## Step 5: Vulnerability Validation
Confirm and document findings:
```python
from exaaiagnt.tools import create_vuln_report
report = create_vuln_report(
    vuln_type="sql_injection",
    url=target_url,
    parameter="id",
    payload="' OR 1=1--",
    evidence="Database error in response"
)
# Generates PoC, CVSS, remediation
```

## Step 6: Report Generation
Compile all confirmed vulnerabilities with:
- Severity ratings
- Proof of Concept
- Remediation guidance
"""


def get_fuzzer_prompt() -> str:
    """Get the fuzzer system prompt."""
    return FUZZER_SYSTEM_PROMPT.strip()


def get_analyzer_prompt() -> str:
    """Get the analyzer system prompt."""
    return ANALYZER_SYSTEM_PROMPT.strip()


def get_validator_prompt() -> str:
    """Get the validator system prompt."""
    return VALIDATOR_SYSTEM_PROMPT.strip()


def get_waf_bypass_prompt() -> str:
    """Get the WAF bypass prompt."""
    return WAF_BYPASS_PROMPT.strip()


def get_security_testing_prompt() -> str:
    """Get the combined security testing workflow prompt."""
    return SECURITY_TESTING_PROMPT.strip()


def get_all_tool_prompts() -> dict[str, str]:
    """Get all tool prompts as a dictionary."""
    return {
        "fuzzer": get_fuzzer_prompt(),
        "analyzer": get_analyzer_prompt(),
        "validator": get_validator_prompt(),
        "waf_bypass": get_waf_bypass_prompt(),
        "security_testing": get_security_testing_prompt(),
    }
