import { Operation } from '@api-client/json/types.js';
import { Model } from '../core/Model.js';
import type SdkService from '../services/SdkService.js';
import type { MediaPatchRevision } from '@api-client/core/patch/types.js';
declare enum ModelState {
    /**
     * Not doing anything.
     */
    idle = 0,
    /**
     * Currently querying for file data.
     */
    reading = 1,
    /**
     * Data received and the result yielded no results or less than the limit.
     */
    ended = 2
}
export interface PatchableFileModelOptions<T> {
    oid: string;
    fid: string;
    sdk: SdkService;
    initialize: (value: unknown, dependencies: unknown[] | undefined) => T;
    bufferDelay?: number;
}
/**
 * A base class for models that represent patchable files.
 * It provides methods to read, apply server patches, and handle changes.
 * The model is designed to work with a file identified by an organization ID (oid)
 * and a file ID (fid).
 *
 * @template T The type of the file content.
 */
export declare abstract class PatchableFileModel<T extends object> extends Model<T> {
    /**
     * This is essentially a snapshot of the document that is
     * always consistent with the server (to our knowledge).
     * It is used to:
     * - compare with the current `value` to generate diff patches
     * - apply server patches once they arrive and then rebased client patches.
     * After that new revision has server and client patches.
     */
    private revision?;
    /**
     * The current state of the model.
     */
    state: ModelState;
    private bufferTimeoutId;
    private readonly bufferDelay;
    protected oid: string;
    protected fid: string;
    protected sdk: SdkService;
    protected initCallback: (value: unknown, dependencies: unknown[] | undefined) => T;
    /**
     * The current file media version.
     */
    protected version: number;
    /**
     * The dependencies of the media object.
     * This is an array of objects that are referenced by the media object.
     * If the media object has no dependencies, this will be `undefined`.
     *
     * This should be manually populated then the application adds a dependency
     * to the media object. There's no way for us to know when a dependency is added
     * or removed from the media object, so we leave it up to the application to
     * manage this array.
     *
     * Note that dependencies are only fetched when the file is read for the first time.
     */
    dependencies: unknown[] | undefined;
    constructor(options: PatchableFileModelOptions<T>);
    read(): Promise<void>;
    /**
     * Tests whether the media object has dependencies.
     * If the media object has a `dependencyList` property that is an array
     * and contains at least one item, it returns a promise that resolves to
     * an array of dependencies. If the `dependencyList` is empty or not an array,
     * it returns a promise that resolves to `undefined`.
     * @param media The media object to read dependencies from.
     */
    readDependencies(media: unknown): Promise<unknown[] | undefined>;
    /**
     * Called when the file was downloaded and the content is ready to be setup.
     * Add any listeners to the content here.
     * @param content The file content to setup.
     */
    protected abstract setupFile(content: T): void;
    protected setupPreviousData(content: T): void;
    /**
     * Applies incoming server patches to the document and rebases client patches.
     *
     * This method integrates server-side changes into the document and reconciles
     * them with any local changes made by the client. It ensures that client
     * changes are applied on top of the latest server state.
     *
     * **Process:**
     *
     * 1.  Applies the `server` patches to the `revision`.
     * 2.  Calculates the client's local changes (diff between `revision` and `value`).
     * 3.  If there are local changes, rebases them against the server patches.
     * 4.  Applies the rebased client patches to the `revision`.
     * 5.  Updates the `value` to match the `revision`.
     * 6. Dispatches `change` event.
     *
     * @param server - The server patches to be applied to the document.
     * @returns The rebased **client** patches that were applied to the document.
     *   These patches are safe to send to the server. Returns an empty array if there were no local changes.
     * @throws {Error} If the local patches cannot be applied to the document after
     *   server changes. This indicates a conflict that the client application
     *   should handle (e.g., by notifying the user and refreshing the document).
     *
     * @example
     * ```typescript
     * const doc = new JsonDocument({ a: 1, b: [2, 3] });
     *
     * // Simulate local changes (UI edits)
     * doc.value.a = 4;
     * doc.value.b.push(5);
     *
     * // Simulate a server patch
     * const serverPatch: Operation[] = [{ op: 'add', path: '/b/0', value: 0 }];
     *
     * // Apply the server patch and rebase local changes
     * const rebasedClientPatches = doc.applyServer(serverPatch);
     *
     * console.log(doc.value); // Output: { a: 4, b: [0, 2, 3, 5] }
     * console.log(rebasedClientPatches);
     * // Output: [{ op: 'replace', path: '/a', value: 4 }, { op: 'add', path: '/b/3', value: 5 }]
     * ```
     */
    applyServerPatch(info: MediaPatchRevision): Operation[];
    /**
     * Called when a change is made to the data object.
     */
    handleChange(): Promise<void>;
    /**
     * Schedules sending the buffered patches to the server after a delay.
     */
    private scheduleSend;
    /**
     * Sends the buffered patches to the server.
     */
    private send;
    private sendPatchToServer;
    /**
     * A function that creates a new revision of the current file.
     */
    protected abstract createRevision(): T;
    /**
     * Returns the current value of the file.
     */
    protected abstract readValue(): T;
    /**
     * Sets the value of the file.
     * @param value The new value to set.
     */
    protected abstract setValue(value: T): void;
    /**
     * Checks whether this contents is identified by the passed `oid` and `fid`
     * @param oid The organization id
     * @param fid The file id
     * @returns Whether the current file is the same as the passed arguments.
     */
    isFile(oid: string, fid: string): boolean;
}
export {};
//# sourceMappingURL=PatchableFileModel.d.ts.map