from dataclasses import dataclass, field
from typing import Any, Optional


@dataclass
class SQLAttempt:
    sql: str
    error: Optional[str] = None
    validation_error: Optional[str] = None
    execution_error: Optional[str] = None


@dataclass
class QueryResult:
    sql: str
    columns: list[str] = field(default_factory=list)
    rows: list[list[Any]] = field(default_factory=list)
    row_count: int = 0
    truncated: bool = False
    error: Optional[str] = None

    @property
    def success(self) -> bool:
        """Return True if the query executed successfully."""
        return self.error is None
