"""Type stubs for hfortix_fortios.client module."""

from __future__ import annotations

from typing import Any, Literal, Optional, overload

from hfortix_core.http.interface import IHTTPClient
from hfortix_fortios.api import API, APIDictMode, APIObjectMode


class FortiOSDictMode:
    """FortiOS client in dict response mode (default).
    
    All endpoint methods return TypedDict types with bracket access (response["field"]).
    """
    
    @property
    def api(self) -> APIDictMode: ...
    @property
    def host(self) -> Optional[str]: ...
    @property
    def port(self) -> Optional[int]: ...
    @property
    def vdom(self) -> Optional[str]: ...
    @property
    def error_mode(self) -> Literal["raise", "return", "print"]: ...
    @property
    def error_format(self) -> Literal["detailed", "simple", "code_only"]: ...
    @property
    def connection_stats(self) -> dict[str, Any]: ...
    @property
    def last_request(self) -> dict[str, Any] | None: ...
    
    def get_connection_stats(self) -> dict[str, Any]: ...
    def get_write_operations(self) -> list[dict[str, Any]]: ...
    def close(self) -> None: ...
    def __enter__(self) -> FortiOSDictMode: ...
    def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ...


class FortiOSObjectMode:
    """FortiOS client in object response mode.
    
    All endpoint methods return Object types with attribute access (response.field).
    """
    
    @property
    def api(self) -> APIObjectMode: ...
    @property
    def host(self) -> Optional[str]: ...
    @property
    def port(self) -> Optional[int]: ...
    @property
    def vdom(self) -> Optional[str]: ...
    @property
    def error_mode(self) -> Literal["raise", "return", "print"]: ...
    @property
    def error_format(self) -> Literal["detailed", "simple", "code_only"]: ...
    @property
    def connection_stats(self) -> dict[str, Any]: ...
    @property
    def last_request(self) -> dict[str, Any] | None: ...
    
    def get_connection_stats(self) -> dict[str, Any]: ...
    def get_write_operations(self) -> list[dict[str, Any]]: ...
    def close(self) -> None: ...
    def __enter__(self) -> FortiOSObjectMode: ...
    def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ...


class FortiOS:
    """FortiOS REST API Client.

    The response_mode parameter determines the return type of all endpoint methods:
    - "dict" (default): Returns TypedDict types with bracket access (response["field"])
    - "object": Returns Object types with attribute access (response.field)
    
    You can also override response_mode per-call on individual endpoint methods.
    """

    # Object mode overloads (must come first - Pylance matches top to bottom)
    @overload
    def __new__(
        cls,
        host: str,
        token: str,
        *,
        mode: Literal["sync", "async"] = ...,
        verify: bool = ...,
        vdom: str | None = ...,
        port: int | None = ...,
        error_mode: Literal["raise", "return", "print"] = ...,
        error_format: Literal["detailed", "simple", "code_only"] = ...,
        response_mode: Literal["object"],
        **kwargs: Any,
    ) -> FortiOSObjectMode: ...
    
    @overload
    def __new__(
        cls,
        host: str,
        *,
        username: str,
        password: str,
        mode: Literal["sync", "async"] = ...,
        verify: bool = ...,
        vdom: str | None = ...,
        port: int | None = ...,
        error_mode: Literal["raise", "return", "print"] = ...,
        error_format: Literal["detailed", "simple", "code_only"] = ...,
        response_mode: Literal["object"],
        **kwargs: Any,
    ) -> FortiOSObjectMode: ...

    # Dict mode overloads (default - comes after object mode)
    @overload
    def __new__(
        cls,
        host: str,
        token: str,
        *,
        mode: Literal["sync", "async"] = ...,
        verify: bool = ...,
        vdom: str | None = ...,
        port: int | None = ...,
        error_mode: Literal["raise", "return", "print"] = ...,
        error_format: Literal["detailed", "simple", "code_only"] = ...,
        response_mode: Literal["dict"] | None = ...,
        **kwargs: Any,
    ) -> FortiOSDictMode: ...
    
    @overload
    def __new__(
        cls,
        host: str,
        *,
        username: str,
        password: str,
        mode: Literal["sync", "async"] = ...,
        verify: bool = ...,
        vdom: str | None = ...,
        port: int | None = ...,
        error_mode: Literal["raise", "return", "print"] = ...,
        error_format: Literal["detailed", "simple", "code_only"] = ...,
        response_mode: Literal["dict"] | None = ...,
        **kwargs: Any,
    ) -> FortiOSDictMode: ...

    # Runtime properties (for when type is FortiOS directly)
    @property
    def api(self) -> API: ...
    @property
    def host(self) -> Optional[str]: ...
    @property
    def port(self) -> Optional[int]: ...
    @property
    def vdom(self) -> Optional[str]: ...
    @property
    def error_mode(self) -> Literal["raise", "return", "print"]: ...
    @property
    def error_format(self) -> Literal["detailed", "simple", "code_only"]: ...
    @property
    def connection_stats(self) -> dict[str, Any]: ...
    @property
    def last_request(self) -> dict[str, Any] | None: ...
    
    def get_connection_stats(self) -> dict[str, Any]: ...
    def get_write_operations(self) -> list[dict[str, Any]]: ...
    def close(self) -> None: ...
    def __enter__(self) -> FortiOS: ...
    def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ...
