from typing import Any, Protocol

from sqlexplore.completion.models import CompletionItem
from sqlexplore.core.engine_models import EngineResponse, HistoryQueryType, QueryHistoryEntry


class CommandEngine(Protocol):
    conn: Any
    table_name: str
    default_limit: int
    max_rows_display: int
    max_value_chars: int
    columns: list[str]
    column_types: dict[str, str]
    executed_sql: list[str]
    query_history: list[QueryHistoryEntry]
    last_sql: str
    last_result_sql: str | None

    @property
    def schema_rows(self) -> list[tuple[Any, ...]]: ...

    def help_text(self) -> str: ...

    def command_specs(self) -> list[Any]: ...

    def lookup_command(self, raw_name: str) -> Any: ...

    def resolve_column(self, raw_column: str) -> str | None: ...

    def run_sql(
        self,
        sql_text: str,
        remember: bool = True,
        add_to_query_history: bool = True,
        query_type: HistoryQueryType = "user_entered_sql",
    ) -> EngineResponse: ...

    def run_input(self, raw_input: str, add_to_query_history: bool = True) -> EngineResponse: ...

    def row_count(self) -> int: ...

    def startup_tables(self) -> list[tuple[str, str, str, int]]: ...

    def table_response(self, columns: list[str], rows: list[tuple[Any, ...]], message: str) -> EngineResponse: ...


class CommandCompletionCatalog(Protocol):
    def complete_sample(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_filter(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_sort(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_group(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_agg(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_top(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_dupes(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_hist(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_crosstab(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_corr(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_profile(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_summary(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_history(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_rerun(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_rows(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_values(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_limit(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...

    def complete_save(self, args: str, trailing_space: bool) -> list[CompletionItem]: ...
