"""Protocol-level constants and default configuration values."""

from __future__ import annotations

from enum import IntEnum
from typing import Final

from pywebtransport import _wtransport

__all__: list[str] = [
    "DEFAULT_ALPN_PROTOCOLS",
    "DEFAULT_BIND_HOST",
    "DEFAULT_CLIENT_MAX_CONNECTIONS",
    "DEFAULT_CLIENT_MAX_SESSIONS",
    "DEFAULT_CLOSE_TIMEOUT",
    "DEFAULT_CONGESTION_CONTROL_ALGORITHM",
    "DEFAULT_CONNECTION_ATTEMPT_DELAY",
    "DEFAULT_CONNECTION_IDLE_TIMEOUT",
    "DEFAULT_CONNECT_TIMEOUT",
    "DEFAULT_DEV_PORT",
    "DEFAULT_ENABLE_STATELESS_RETRY",
    "DEFAULT_FLOW_CONTROL_WINDOW_AUTO_SCALE",
    "DEFAULT_FLOW_CONTROL_WINDOW_SIZE",
    "DEFAULT_INITIAL_MAX_DATA",
    "DEFAULT_INITIAL_MAX_STREAMS_BIDI",
    "DEFAULT_INITIAL_MAX_STREAMS_UNI",
    "DEFAULT_KEEP_ALIVE",
    "DEFAULT_LOG_LEVEL",
    "DEFAULT_MAX_CAPSULE_SIZE",
    "DEFAULT_MAX_CONNECTION_RETRIES",
    "DEFAULT_MAX_DATAGRAM_SIZE",
    "DEFAULT_MAX_EVENT_HISTORY_SIZE",
    "DEFAULT_MAX_EVENT_LISTENERS",
    "DEFAULT_MAX_EVENT_QUEUE_SIZE",
    "DEFAULT_MAX_MESSAGE_SIZE",
    "DEFAULT_MAX_PENDING_EVENTS_PER_SESSION",
    "DEFAULT_MAX_RETRY_DELAY",
    "DEFAULT_MAX_STREAM_READ_BUFFER",
    "DEFAULT_MAX_STREAM_WRITE_BUFFER",
    "DEFAULT_MAX_TOTAL_PENDING_EVENTS",
    "DEFAULT_PENDING_EVENT_TTL",
    "DEFAULT_READ_TIMEOUT",
    "DEFAULT_RESOURCE_CLEANUP_INTERVAL",
    "DEFAULT_RETRY_BACKOFF",
    "DEFAULT_RETRY_DELAY",
    "DEFAULT_SERVER_MAX_CONNECTIONS",
    "DEFAULT_SERVER_MAX_SESSIONS",
    "DEFAULT_STREAM_CREATION_TIMEOUT",
    "DEFAULT_TRANSPORT_STREAMS_CAP",
    "DEFAULT_WRITE_TIMEOUT",
    "ErrorCodes",
    "MAX_DATAGRAM_SIZE",
    "MAX_PROTOCOL_STREAMS_LIMIT",
    "SUPPORTED_CONGESTION_CONTROL_ALGORITHMS",
]

DEFAULT_ALPN_PROTOCOLS: Final[list[str]] = _wtransport.DEFAULT_ALPN_PROTOCOLS
DEFAULT_BIND_HOST: Final[str] = _wtransport.DEFAULT_BIND_HOST
DEFAULT_CLIENT_MAX_CONNECTIONS: Final[int] = _wtransport.DEFAULT_CLIENT_MAX_CONNECTIONS
DEFAULT_CLIENT_MAX_SESSIONS: Final[int] = _wtransport.DEFAULT_CLIENT_MAX_SESSIONS
DEFAULT_CLOSE_TIMEOUT: Final[float] = _wtransport.DEFAULT_CLOSE_TIMEOUT
DEFAULT_CONGESTION_CONTROL_ALGORITHM: Final[str] = _wtransport.DEFAULT_CONGESTION_CONTROL_ALGORITHM
DEFAULT_CONNECTION_ATTEMPT_DELAY: Final[float] = _wtransport.DEFAULT_CONNECTION_ATTEMPT_DELAY
DEFAULT_CONNECTION_IDLE_TIMEOUT: Final[float] = _wtransport.DEFAULT_CONNECTION_IDLE_TIMEOUT
DEFAULT_CONNECT_TIMEOUT: Final[float] = _wtransport.DEFAULT_CONNECT_TIMEOUT
DEFAULT_DEV_PORT: Final[int] = _wtransport.DEFAULT_DEV_PORT
DEFAULT_ENABLE_STATELESS_RETRY: Final[bool] = _wtransport.DEFAULT_ENABLE_STATELESS_RETRY
DEFAULT_FLOW_CONTROL_WINDOW_AUTO_SCALE: Final[bool] = _wtransport.DEFAULT_FLOW_CONTROL_WINDOW_AUTO_SCALE
DEFAULT_FLOW_CONTROL_WINDOW_SIZE: Final[int] = _wtransport.DEFAULT_FLOW_CONTROL_WINDOW_SIZE
DEFAULT_INITIAL_MAX_DATA: Final[int] = _wtransport.DEFAULT_INITIAL_MAX_DATA
DEFAULT_INITIAL_MAX_STREAMS_BIDI: Final[int] = _wtransport.DEFAULT_INITIAL_MAX_STREAMS_BIDI
DEFAULT_INITIAL_MAX_STREAMS_UNI: Final[int] = _wtransport.DEFAULT_INITIAL_MAX_STREAMS_UNI
DEFAULT_KEEP_ALIVE: Final[float] = _wtransport.DEFAULT_KEEP_ALIVE
DEFAULT_LOG_LEVEL: Final[str] = _wtransport.DEFAULT_LOG_LEVEL
DEFAULT_MAX_CAPSULE_SIZE: Final[int] = _wtransport.DEFAULT_MAX_CAPSULE_SIZE
DEFAULT_MAX_CONNECTION_RETRIES: Final[int] = _wtransport.DEFAULT_MAX_CONNECTION_RETRIES
DEFAULT_MAX_DATAGRAM_SIZE: Final[int] = _wtransport.DEFAULT_MAX_DATAGRAM_SIZE
DEFAULT_MAX_EVENT_HISTORY_SIZE: Final[int] = _wtransport.DEFAULT_MAX_EVENT_HISTORY_SIZE
DEFAULT_MAX_EVENT_LISTENERS: Final[int] = _wtransport.DEFAULT_MAX_EVENT_LISTENERS
DEFAULT_MAX_EVENT_QUEUE_SIZE: Final[int] = _wtransport.DEFAULT_MAX_EVENT_QUEUE_SIZE
DEFAULT_MAX_MESSAGE_SIZE: Final[int] = _wtransport.DEFAULT_MAX_MESSAGE_SIZE
DEFAULT_MAX_PENDING_EVENTS_PER_SESSION: Final[int] = _wtransport.DEFAULT_MAX_PENDING_EVENTS_PER_SESSION
DEFAULT_MAX_RETRY_DELAY: Final[float] = _wtransport.DEFAULT_MAX_RETRY_DELAY
DEFAULT_MAX_STREAM_READ_BUFFER: Final[int] = _wtransport.DEFAULT_MAX_STREAM_READ_BUFFER
DEFAULT_MAX_STREAM_WRITE_BUFFER: Final[int] = _wtransport.DEFAULT_MAX_STREAM_WRITE_BUFFER
DEFAULT_MAX_TOTAL_PENDING_EVENTS: Final[int] = _wtransport.DEFAULT_MAX_TOTAL_PENDING_EVENTS
DEFAULT_PENDING_EVENT_TTL: Final[float] = _wtransport.DEFAULT_PENDING_EVENT_TTL
DEFAULT_READ_TIMEOUT: Final[float] = _wtransport.DEFAULT_READ_TIMEOUT
DEFAULT_RESOURCE_CLEANUP_INTERVAL: Final[float] = _wtransport.DEFAULT_RESOURCE_CLEANUP_INTERVAL
DEFAULT_RETRY_BACKOFF: Final[float] = _wtransport.DEFAULT_RETRY_BACKOFF
DEFAULT_RETRY_DELAY: Final[float] = _wtransport.DEFAULT_RETRY_DELAY
DEFAULT_SERVER_MAX_CONNECTIONS: Final[int] = _wtransport.DEFAULT_SERVER_MAX_CONNECTIONS
DEFAULT_SERVER_MAX_SESSIONS: Final[int] = _wtransport.DEFAULT_SERVER_MAX_SESSIONS
DEFAULT_STREAM_CREATION_TIMEOUT: Final[float] = _wtransport.DEFAULT_STREAM_CREATION_TIMEOUT
DEFAULT_TRANSPORT_STREAMS_CAP: Final[int] = _wtransport.DEFAULT_TRANSPORT_STREAMS_CAP
DEFAULT_WRITE_TIMEOUT: Final[float] = _wtransport.DEFAULT_WRITE_TIMEOUT
SUPPORTED_CONGESTION_CONTROL_ALGORITHMS: Final[list[str]] = _wtransport.SUPPORTED_CONGESTION_CONTROL_ALGORITHMS
MAX_DATAGRAM_SIZE: Final[int] = _wtransport.MAX_DATAGRAM_SIZE
MAX_PROTOCOL_STREAMS_LIMIT: Final[int] = _wtransport.MAX_PROTOCOL_STREAMS_LIMIT


class ErrorCodes(IntEnum):
    """Enumeration of WebTransport and HTTP/3 error codes."""

    AEAD_LIMIT_REACHED = _wtransport.ERR_AEAD_LIMIT_REACHED
    APP_AUTHENTICATION_FAILED = _wtransport.ERR_APP_AUTHENTICATION_FAILED
    APP_CONNECTION_TIMEOUT = _wtransport.ERR_APP_CONNECTION_TIMEOUT
    APP_INVALID_REQUEST = _wtransport.ERR_APP_INVALID_REQUEST
    APP_PERMISSION_DENIED = _wtransport.ERR_APP_PERMISSION_DENIED
    APP_RESOURCE_EXHAUSTED = _wtransport.ERR_APP_RESOURCE_EXHAUSTED
    APP_SERVICE_UNAVAILABLE = _wtransport.ERR_APP_SERVICE_UNAVAILABLE
    APPLICATION_ERROR = _wtransport.ERR_APPLICATION_ERROR
    CONNECTION_ID_LIMIT_ERROR = _wtransport.ERR_CONNECTION_ID_LIMIT_ERROR
    CONNECTION_REFUSED = _wtransport.ERR_CONNECTION_REFUSED
    CRYPTO_BUFFER_EXCEEDED = _wtransport.ERR_CRYPTO_BUFFER_EXCEEDED
    FINAL_SIZE_ERROR = _wtransport.ERR_FINAL_SIZE_ERROR
    FLOW_CONTROL_ERROR = _wtransport.ERR_FLOW_CONTROL_ERROR
    FRAME_ENCODING_ERROR = _wtransport.ERR_FRAME_ENCODING_ERROR
    H3_CLOSED_CRITICAL_STREAM = _wtransport.ERR_H3_CLOSED_CRITICAL_STREAM
    H3_CONNECT_ERROR = _wtransport.ERR_H3_CONNECT_ERROR
    H3_DATAGRAM_ERROR = _wtransport.ERR_H3_DATAGRAM_ERROR
    H3_EXCESSIVE_LOAD = _wtransport.ERR_H3_EXCESSIVE_LOAD
    H3_FRAME_ERROR = _wtransport.ERR_H3_FRAME_ERROR
    H3_FRAME_UNEXPECTED = _wtransport.ERR_H3_FRAME_UNEXPECTED
    H3_GENERAL_PROTOCOL_ERROR = _wtransport.ERR_H3_GENERAL_PROTOCOL_ERROR
    H3_ID_ERROR = _wtransport.ERR_H3_ID_ERROR
    H3_INTERNAL_ERROR = _wtransport.ERR_H3_INTERNAL_ERROR
    H3_MESSAGE_ERROR = _wtransport.ERR_H3_MESSAGE_ERROR
    H3_MISSING_SETTINGS = _wtransport.ERR_H3_MISSING_SETTINGS
    H3_NO_ERROR = _wtransport.ERR_H3_NO_ERROR
    H3_REQUEST_CANCELLED = _wtransport.ERR_H3_REQUEST_CANCELLED
    H3_REQUEST_INCOMPLETE = _wtransport.ERR_H3_REQUEST_INCOMPLETE
    H3_REQUEST_REJECTED = _wtransport.ERR_H3_REQUEST_REJECTED
    H3_SETTINGS_ERROR = _wtransport.ERR_H3_SETTINGS_ERROR
    H3_STREAM_CREATION_ERROR = _wtransport.ERR_H3_STREAM_CREATION_ERROR
    H3_VERSION_FALLBACK = _wtransport.ERR_H3_VERSION_FALLBACK
    INTERNAL_ERROR = _wtransport.ERR_INTERNAL_ERROR
    INVALID_TOKEN = _wtransport.ERR_INVALID_TOKEN
    KEY_UPDATE_ERROR = _wtransport.ERR_KEY_UPDATE_ERROR
    LIB_CONNECTION_STATE_ERROR = _wtransport.ERR_LIB_CONNECTION_STATE_ERROR
    LIB_INTERNAL_ERROR = _wtransport.ERR_LIB_INTERNAL_ERROR
    LIB_SESSION_STATE_ERROR = _wtransport.ERR_LIB_SESSION_STATE_ERROR
    LIB_STREAM_STATE_ERROR = _wtransport.ERR_LIB_STREAM_STATE_ERROR
    NO_ERROR = _wtransport.ERR_NO_ERROR
    NO_VIABLE_PATH = _wtransport.ERR_NO_VIABLE_PATH
    PROTOCOL_VIOLATION = _wtransport.ERR_PROTOCOL_VIOLATION
    QPACK_DECODER_STREAM_ERROR = _wtransport.ERR_QPACK_DECODER_STREAM_ERROR
    QPACK_DECOMPRESSION_FAILED = _wtransport.ERR_QPACK_DECOMPRESSION_FAILED
    QPACK_ENCODER_STREAM_ERROR = _wtransport.ERR_QPACK_ENCODER_STREAM_ERROR
    STREAM_LIMIT_ERROR = _wtransport.ERR_STREAM_LIMIT_ERROR
    STREAM_STATE_ERROR = _wtransport.ERR_STREAM_STATE_ERROR
    TRANSPORT_PARAMETER_ERROR = _wtransport.ERR_TRANSPORT_PARAMETER_ERROR
    WT_ALPN_ERROR = _wtransport.ERR_WT_ALPN_ERROR
    WT_APPLICATION_ERROR_FIRST = _wtransport.ERR_WT_APPLICATION_ERROR_FIRST
    WT_APPLICATION_ERROR_LAST = _wtransport.ERR_WT_APPLICATION_ERROR_LAST
    WT_BUFFERED_STREAM_REJECTED = _wtransport.ERR_WT_BUFFERED_STREAM_REJECTED
    WT_FLOW_CONTROL_ERROR = _wtransport.ERR_WT_FLOW_CONTROL_ERROR
    WT_REQUIREMENTS_NOT_MET = _wtransport.ERR_WT_REQUIREMENTS_NOT_MET
    WT_SESSION_GONE = _wtransport.ERR_WT_SESSION_GONE
