"""
Constants for Seigr Toolset Transmissions.
"""

# Protocol constants
STT_MAGIC = b'ST'  # 0x53 0x54
STT_VERSION = 1

# Frame types
STT_FRAME_TYPE_DATA = 0x01
STT_FRAME_TYPE_CONTROL = 0x02
STT_FRAME_TYPE_STREAM = 0x03
STT_FRAME_TYPE_AUTH = 0x04
STT_FRAME_TYPE_HANDSHAKE = 0x05

# Frame flags
STT_FLAG_NONE = 0x00
STT_FLAG_FRAGMENT = 0x01
STT_FLAG_STREAM_INIT = 0x02
STT_FLAG_STREAM_END = 0x04
STT_FLAG_STREAM_SEGMENT = 0x08  # Binary segment (MTU optimization, not semantic chunk)
STT_FLAG_PRIORITY_HIGH = 0x10
STT_FLAG_PRIORITY_LOW = 0x20

# Handshake message types
STT_HANDSHAKE_HELLO = 0x01
STT_HANDSHAKE_HELLO_RESP = 0x02
STT_HANDSHAKE_SESSION_INIT = 0x03
STT_HANDSHAKE_AUTH_PROOF = 0x04

# Control message types
STT_CONTROL_PING = 0x01
STT_CONTROL_PONG = 0x02
STT_CONTROL_FLOW_CREDIT = 0x03
STT_CONTROL_KEY_ROTATION = 0x04
STT_CONTROL_SESSION_CLOSE = 0x05
STT_CONTROL_ERROR = 0x06

# Stream states
STT_STREAM_STATE_IDLE = 0
STT_STREAM_STATE_OPEN = 1
STT_STREAM_STATE_HALF_CLOSED = 2
STT_STREAM_STATE_CLOSED = 3

# Session states
STT_SESSION_STATE_INIT = 0
STT_SESSION_STATE_HANDSHAKE = 1
STT_SESSION_STATE_ACTIVE = 2
STT_SESSION_STATE_KEY_ROTATING = 3
STT_SESSION_STATE_CLOSING = 4
STT_SESSION_STATE_CLOSED = 5

# Limits and thresholds
STT_MAX_FRAME_SIZE = 2 * 1024 * 1024  # 2 MB (accommodates STC metadata ~1.5MB + payload)
STT_MAX_PAYLOAD_SIZE = 1024 * 1024  # 1 MB payload max
STT_SESSION_ID_LENGTH = 8
STT_SEQUENCE_LENGTH = 8
STT_TIMESTAMP_LENGTH = 8
STT_RESERVED_LENGTH = 2
STT_STREAM_ID_LENGTH = 4

# Key rotation thresholds
STT_KEY_ROTATION_DATA_THRESHOLD = 100 * 1024 * 1024  # 100 MB
STT_KEY_ROTATION_TIME_THRESHOLD = 3600  # 1 hour in seconds
STT_KEY_ROTATION_MESSAGE_THRESHOLD = 10000  # messages

# Session management
STT_SESSION_TIMEOUT = 300  # 5 minutes
STT_SESSION_MAX_IDLE = 600  # 10 minutes
STT_RESUMPTION_TOKEN_LIFETIME = 86400  # 24 hours

# Transport settings
STT_DEFAULT_TCP_PORT = 9000
STT_DEFAULT_UDP_PORT = 9001
STT_DEFAULT_WS_PORT = 8080
STT_BACKLOG = 128
STT_BUFFER_SIZE = 8192

# Flow control
STT_INITIAL_STREAM_CREDIT = 65536  # 64 KB
STT_INITIAL_SESSION_CREDIT = 1048576  # 1 MB
STT_MIN_CREDIT_THRESHOLD = 16384  # 16 KB

# Capabilities
STT_CAP_STREAMS = 0x01
STT_CAP_KEY_ROTATION = 0x02
STT_CAP_SESSION_RESUMPTION = 0x04
STT_CAP_FLOW_CONTROL = 0x08
STT_CAP_COMPRESSION = 0x10  # Future use

# Error codes
STT_ERROR_NONE = 0x00
STT_ERROR_PROTOCOL = 0x01
STT_ERROR_CRYPTO = 0x02
STT_ERROR_SESSION = 0x03
STT_ERROR_STREAM = 0x04
STT_ERROR_FLOW_CONTROL = 0x05
STT_ERROR_INTERNAL = 0xFF

# Logging levels
STT_LOG_LEVEL_DEBUG = 10
STT_LOG_LEVEL_INFO = 20
STT_LOG_LEVEL_WARNING = 30
STT_LOG_LEVEL_ERROR = 40
STT_LOG_LEVEL_CRITICAL = 50
