// @ts-nocheck
import { CrdtGetDataQuery, CrdtGetMessagesQuery, CrdtGetSnapshotQuery, CrdtGetVersionQuery, CrdtGetVersionsQuery, CrdtMessageData, CrdtOnDataChangeQuery, CrdtOnMessageQuery, CrdtOnPresenceChangeQuery, CrdtOnRegisteredUserChangeQuery, CrdtOnStateChangeQuery, CrdtPruneMessagesQuery, CrdtPushMessageQuery, CrdtRegisterSyncUserQuery, CrdtSaveSnapshotQuery, CrdtSetPresenceQuery, CrdtSaveVersionQuery, CrdtSnapshotData, CrdtUpdateDataQuery, CrdtUpdateStateQuery } from "../data/crdt.data.model";
import { CrdtEventTypesMap } from "../data/crdt-events.data.model";

export declare class CrdtElement {
    /**
     * Update data for a specific CRDT document
     * @param id Document ID
     * @param state State data as Uint8Array or number array
     */
    updateData: (updateDataQuery: CrdtUpdateDataQuery) => Promise<any>;

    /**
     * Subscribe to data changes for a specific CRDT document
     * @param id Document ID
     * @param callback Callback function to handle data changes
     * @returns Unsubscribe function
     */
    onDataChange: (onDataChangeQuery: CrdtOnDataChangeQuery) => () => void;

    /**
     * Get data for a specific CRDT document
     * @param id Document ID
     */
    getData: (getDataQuery: CrdtGetDataQuery) => Promise<any>;

    /**
     * Subscribe to state changes for a specific CRDT document
     * @param id Document ID
     * @param callback Callback function to handle state changes
     * @returns Unsubscribe function
     */
    onStateChange: (onStateChangeQuery: CrdtOnStateChangeQuery) => () => void;

    /**
     * Update state for a specific CRDT document
     * @param id Document ID
     * @param state State data as Uint8Array or number array
     */
    updateState: (updateStateQuery: CrdtUpdateStateQuery) => Promise<any>;

    /**
     * Register a user for synchronization on a specific CRDT document
     * @param id Document ID
     */
    registerSyncUser: (registerSyncUserQuery: CrdtRegisterSyncUserQuery) => Promise<void>;

    /**
     * Subscribe to registered user changes for a specific CRDT document
     */
    onRegisteredUserChange: (onRegisteredUserChangeQuery: CrdtOnRegisteredUserChangeQuery) => () => void;

    /**
     * Set presence for a specific CRDT document
     * @param id Document ID
     */
    setPresence: (setPresenceQuery: CrdtSetPresenceQuery) => Promise<void>;

    /**
     * Subscribe to presence changes for a specific CRDT document
     * @param id Document ID
     * @param callback Callback function to handle presence changes
     * @returns Unsubscribe function
     */
    onPresenceChange: (onPresenceChangeQuery: CrdtOnPresenceChangeQuery) => () => void;

    /**
     * Store a version of a specific CRDT document
     * @param id Document ID
     * @param versionId Version ID
     * @param versionName Version name
     * @param state State data as Uint8Array or number array
     */
    saveVersion: (saveVersionQuery: CrdtSaveVersionQuery) => Promise<any>;

    /**
     * Get a version of a specific CRDT document
     * @param id Document ID
     * @param versionId Version ID
     */
    getVersion: (getVersionQuery: CrdtGetVersionQuery) => Promise<any>;

    /**
     * Get all versions of a specific CRDT document
     * @param id Document ID
     */
    getVersions: (getVersionsQuery: CrdtGetVersionsQuery) => Promise<any>;

    /**
     * Enable webhook
     */
    enableWebhook: () => void;

    /**
     * Disable webhook
     */
    disableWebhook: () => void;

    /**
     * Set webhook debounce time
     * @param time debounce time in milliseconds
     */
    setWebhookDebounceTime: (time: number) => void;

    /**
     * Push a lib0-encoded message to the unified message stream.
     * Uses Firebase push() for chronologically-ordered keys.
     * Carries both sync (type 0) and awareness (type 1) messages.
     * @param pushMessageQuery - contains id, data (encoded bytes), yjsClientId (Y.Doc client ID), optional messageType and eventData
     */
    pushMessage: (pushMessageQuery: CrdtPushMessageQuery) => Promise<void>;
    /**
     * Subscribe to the unified message stream for real-time sync.
     * Emits each new message individually as it arrives (streaming pattern).
     * Returns an unsubscribe function.
     * @param onMessageQuery - contains id, callback, and optional afterTs for filtering
     */
    onMessage: (onMessageQuery: CrdtOnMessageQuery) => () => void;
    /**
     * Fetch all messages after a given timestamp (one-time read).
     * Used for message replay during initial load (y-redis pattern).
     * @param getMessagesQuery - contains id and optional afterTs
     */
    getMessages: (getMessagesQuery: CrdtGetMessagesQuery) => Promise<CrdtMessageData[]>;
    /**
     * Get the latest full-state snapshot for a document.
     * Used as the baseline for message replay during initial load.
     * @param getSnapshotQuery - contains id
     */
    getSnapshot: (getSnapshotQuery: CrdtGetSnapshotQuery) => Promise<CrdtSnapshotData | null>;
    /**
     * Save a full-state snapshot (state + vector) for fast initial load.
     * Called periodically to create checkpoints, enabling message pruning.
     * @param saveSnapshotQuery - contains id, state (Y.Doc update), and vector (state vector)
     */
    saveSnapshot: (saveSnapshotQuery: CrdtSaveSnapshotQuery) => Promise<void>;
    /**
     * Remove messages older than the given timestamp from the message stream.
     * Called after saving a snapshot to keep the message stream bounded.
     * @param pruneMessagesQuery - contains id and beforeTs
     */
    pruneMessages: (pruneMessagesQuery: CrdtPruneMessagesQuery) => Promise<void>;

    /**
     * To set activity debounce time for batching CRDT edits (Default value is 10 minutes)
     * @param time debounce time in milliseconds (minimum: 10 seconds)
     */
    setActivityDebounceTime: (time: number) => void;

    /**
     * Subscribe to crdt actions
     * @param action Action to subscribe to
     * @returns Observable of the action
     */
    on: <T extends keyof CrdtEventTypesMap>(action: T) => Observable<CrdtEventTypesMap[T]>;

    constructor();

    /**
     * Update data for a specific CRDT document
     * @param id Document ID
     * @param state State data as Uint8Array or number array
     */
    private _updateData;

    /**
     * Subscribe to data changes for a specific CRDT document
     * @param id Document ID
     * @param callback Callback function to handle data changes
     * @returns Unsubscribe function
     */
    private _onDataChange;

    /**
     * Get data for a specific CRDT document
     * @param id Document ID
     */
    private _getData;

    /**
     * Subscribe to state changes for a specific CRDT document
     * @param id Document ID
     * @param callback Callback function to handle state changes
     * @returns Unsubscribe function
     */
    private _onStateChange;

    /**
     * Update state for a specific CRDT document
     * @param id Document ID
     * @param state State data as Uint8Array or number array
     */
    private _updateState;

    /**
     * Register a user for synchronization on a specific CRDT document
     * @param id Document ID
     */
    private _registerSyncUser;

    /**
     * Subscribe to registered user changes for a specific CRDT document
     */
    private _onRegisteredUserChange;

    /**
     * Set presence for a specific CRDT document
     * @param id Document ID
     */
    private _setPresence;

    /**
     * Subscribe to presence changes for a specific CRDT document
     * @param id Document ID
     * @param callback Callback function to handle presence changes
     * @returns Unsubscribe function
     */
    private _onPresenceChange;

    /**
     * Store a version of a specific CRDT document
     * @param id Document ID
     * @param versionId Version ID
     * @param versionName Version name
     * @param state State data as Uint8Array or number array
     */
    private _saveVersion;

    /**
     * Get a version of a specific CRDT document
     * @param id Document ID
     * @param versionId Version ID
     */
    private _getVersion;

    /**
     * Get all versions of a specific CRDT document
     * @param id Document ID
     */
    private _getVersions;

    /**
     * Push a message to the unified message stream
     */
    private _pushMessage;

    /**
     * Subscribe to the unified message stream
     */
    private _onMessage;

    /**
     * Fetch all messages after a given timestamp
     */
    private _getMessages;

    /**
     * Get the latest snapshot for a document
     */
    private _getSnapshot;

    /**
     * Save a full-state snapshot
     */
    private _saveSnapshot;

    /**
     * Remove messages older than a given timestamp
     */
    private _pruneMessages;

    /**
     * Enable webhook
     */
    private _enableWebhook;

    /**
     * Disable webhook
     */
    private _disableWebhook;

    /**
     * Set webhook debounce time
     * @param time debounce time in milliseconds
     */
    private _setWebhookDebounceTime;

    /**
     * Set activity debounce time for batching CRDT edits
     * @param time debounce time in milliseconds (minimum: 10 seconds)
     */
    private _setActivityDebounceTime;

    /**
     * Subscribe to crdt actions
     * @param action Action to subscribe to
     * @returns Observable of the action
     */
    private _on;
}