import Foundation

/// Centralized protocol constants matching the Desktop reference implementation.
enum ProtocolConstants {
    /// Auto-reconnect initial delay in seconds (exponential backoff: 1, 2, 4, 8, 16).
    static let reconnectIntervalS: TimeInterval = 1

    /// Number of messages loaded per batch (scroll-to-top pagination).
    static let maxMessagesLoad = 20

    /// Maximum messages kept in memory per dialog.
    /// Android: unlimited in SQLite, 500 in-memory cache.
    /// Desktop: MESSAGE_MAX_LOADED = 40 (but stores all in IndexedDB).
    /// iOS: keep 200 in memory + persist to disk. Phase 2: SQLite + pagination.
    static let messageMaxCached = 200

    /// Outgoing message delivery timeout in seconds.
    /// If a WAITING message is older than this, mark it as ERROR.
    static let messageDeliveryTimeoutS: Int64 = 80

    /// Maximum number of file attachments per message.
    static let maxAttachmentsInMessage = 5

    /// Number of recent messages checked to determine `is_request` status.
    /// Desktop: `DIALOG_DROP_TO_REQUESTS_IF_NO_MESSAGES_FROM_ME_COUNT = 30`.
    static let dialogDropToRequestsMessageCount = 30

    /// Minimum time between avatar rendering in message list (seconds).
    static let avatarNoRenderTimeDiffS = 300

    /// Maximum upload file size in megabytes.
    static let maxUploadFilesizeMB = 1024

    /// Maximum number of pinned dialogs per account.
    static let maxPinnedDialogs = 3

    /// Outgoing message retry delay in seconds.
    static let outgoingRetryDelayS: TimeInterval = 4

    /// Maximum number of outgoing message retry attempts.
    static let maxOutgoingRetryAttempts = 3

    /// Typing indicator throttle interval in milliseconds (desktop parity).
    static let typingThrottleMs: Int64 = 3_000

    /// Typing indicator display timeout in seconds.
    static let typingDisplayTimeoutS: TimeInterval = 3
}
