"""
Data models for the Exploit Automation Engine (LogicPwn)
- Reuses RequestConfig from logicpwn.models.request_config
- Designed for extensibility, maintainability, and interoperability
"""

from typing import List, Dict, Optional, Any, Union
from enum import Enum
from pydantic import BaseModel, Field
from logicpwn.models.request_config import RequestConfig

class ExploitStatus(str, Enum):
    PENDING = "pending"
    RUNNING = "running"
    SUCCESS = "success"
    FAILED = "failed"
    ABORTED = "aborted"

class PayloadType(str, Enum):
    STATIC = "static"
    DYNAMIC = "dynamic"
    TEMPLATE = "template"
    RANDOM = "random"
    FUZZ = "fuzz"

class PayloadInjectionPoint(BaseModel):
    location: str  # "url", "headers", "body", "json_path", "form_data"
    target_field: str
    payload_type: PayloadType
    payload_value: str
    encoding: Optional[str] = None  # "url", "base64", "html"

class ExploitStep(BaseModel):
    name: str
    description: str
    request_config: RequestConfig
    success_indicators: List[str]
    failure_indicators: List[str] = []
    required_session_state: Optional[Dict[str, Any]] = None
    payload_injection_points: Optional[List[PayloadInjectionPoint]] = None
    delay_after_step: Optional[float] = 0.0
    retry_count: int = 1
    critical: bool = False

class ExploitChain(BaseModel):
    name: str
    description: str
    steps: List[ExploitStep]
    session_state: Dict[str, Any] = Field(default_factory=dict)
    execution_log: List[Any] = Field(default_factory=list)

class ValidationResult(BaseModel):
    is_valid: bool
    reasons: List[str] = []
    matched_indicators: List[str] = []
    failed_indicators: List[str] = []
    extracted_data: Dict[str, Any] = Field(default_factory=dict)

class ExploitResult(BaseModel):
    step_name: str
    status: ExploitStatus
    response: Optional[Any] = None  # Should be requests.Response or RequestResult
    validation_result: Optional[ValidationResult] = None
    error_message: Optional[str] = None
    execution_time: float = 0.0
    extracted_data: Dict[str, Any] = Field(default_factory=dict) 