import datetime
from typing import Any

import pep249
from pyro_mysql.sync import Opts

# ─── Constants ────────────────────────────────────────────────────────────────

apilevel: str = ...
threadsafety: int = ...
paramstyle: str = ...

# ─── Error ────────────────────────────────────────────────────────────────────

class Warning(Exception): ...
class Error(Exception): ...
class InterfaceError(Error): ...
class DatabaseError(Error): ...
class DataError(DatabaseError): ...
class OperationalError(DatabaseError): ...
class IntegrityError(DatabaseError): ...
class InternalError(DatabaseError): ...
class ProgrammingError(DatabaseError): ...
class NotSupportedError(DatabaseError): ...

# ─── Connection ───────────────────────────────────────────────────────────────

def connect(url_or_opts: str | Opts, autocommit: bool | None = False) -> Connection:
    """
    Create a DB-API 2.0 compliant connection to a MySQL server.

    Args:
        url_or_opts: MySQL connection URL (e.g., 'mysql://user:password@host:port/database')
            or Opts object with connection configuration.
        autocommit: If True, enable autocommit mode. If None, use server default. Defaults to False.

    Returns:
        A DB-API 2.0 compliant Connection object.

    Example:
        >>> import pyro_mysql.dbapi as dbapi
        >>> conn = dbapi.connect('mysql://root:password@localhost:3306/mydb')
        >>> cursor = conn.cursor()
        >>> cursor.execute('SELECT 1')
        >>> result = cursor.fetchone()
    """
    ...

class Connection(pep249.Connection):
    # Helper methods
    def ping(self): ...
    def set_autocommit(self, on: bool): ...
    def last_insert_id(self) -> int | None: ...
    def is_closed(self) -> bool: ...

class Cursor(pep249.Cursor):
    # PEP-249 optional extensions
    def __iter__(self) -> "Cursor": ...
    def __next__(self) -> tuple[Any, ...] | None: ...

# ─── Type Constructor ─────────────────────────────────────────────────────────

def Date(year: int, month: int, day: int) -> datetime.date: ...
def Time(hour: int, minute: int, second: int) -> datetime.time: ...
def Timestamp(
    year: int, month: int, day: int, hour: int, minute: int, second: int
) -> datetime.datetime: ...
def DateFromTicks(ticks: int) -> datetime.date: ...
def TimeFromTicks(ticks: int) -> datetime.time: ...
def TimestampFromTicks(ticks: int) -> datetime.datetime: ...
def Binary(x: Any) -> bytes: ...

# ─── Sqlalchemy Compatibility ─────────────────────────────────────────────────

def __getattr__(self, attr: str) -> Any: ...
