/**
 * NOTE: Added reference types here to avoid a `pnpm` bug during build.
 * https://github.com/enboxorg/enbox/pull/507
 */
import type { DwnDateSort, DwnMessage, DwnMessageDescriptor, DwnPaginationCursor, DwnResponseStatus, EnboxAgent, PermissionsApi } from '@enbox/agent';
import type { RecordDeleteParams, RecordModel, RecordOptions, RecordUpdateParams } from './record-types.js';
import { DwnInterface } from '@enbox/agent';
import type { RecordData } from './record-data.js';
export type { ImmutableRecordProperties, OptionalRecordProperties, RecordDeleteParams, RecordModel, RecordOptions, RecordUpdateParams, } from './record-types.js';
export type { RecordData } from './record-data.js';
/**
 * The result of a {@link Record.update} operation.
 *
 * @beta
 */
export type RecordUpdateResult = DwnResponseStatus & {
    /** The updated Record instance reflecting the new state. */
    record: Record;
};
/**
 * The result of a {@link Record.delete} operation.
 *
 * @beta
 */
export type RecordDeleteResult = DwnResponseStatus & {
    /** The deleted Record instance reflecting the deleted state. */
    record: Record;
};
/**
 * The `Record` class encapsulates a single record's data and metadata, providing a more
 * developer-friendly interface for working with Decentralized Web Node (DWN) records.
 *
 * Methods are provided to read, update, and manage the record's lifecycle, including writing to
 * remote DWNs.
 *
 * Note: The DWN SDK's `messageTimestamp` is exposed as `timestamp` on
 *       the Record class. It represents the time of the most recent
 *       message (create, update, or delete) for this logical record.
 *
 * @beta
 */
export declare class Record implements RecordModel {
    /**
     * Cache to minimize the amount of redundant two-phase commits we do in store() and send()
     * Retains awareness of the last 100 records stored/sent for up to 100 target DIDs each.
     */
    private static readonly _sendCache;
    /** The {@link EnboxAgent} instance that handles DWNs requests. */
    private readonly _agent;
    /** The DID of the DWN tenant under which operations are being performed. */
    private readonly _connectedDid;
    /** The optional DID that is delegated to act on behalf of the connectedDid */
    private readonly _delegateDid?;
    /** cache for fetching a permission {@link PermissionGrant}, keyed by a specific MessageType and protocol */
    private readonly _permissionsApi;
    /** Encoded data of the record, if available. */
    private _encodedData?;
    /** Stream of the record's data (Web ReadableStream for cross-platform compatibility). */
    private _readableStream?;
    /** The origin DID if the record was fetched from a remote DWN. */
    private readonly _remoteOrigin?;
    /** The DID of the entity that most recently authored or deleted the record. */
    private readonly _author;
    /** The DID of the entity that originally created the record. */
    private readonly _creator;
    /** Attestation JWS signature. */
    private _attestation?;
    /** Authorization signature(s). */
    private _authorization?;
    /** Context ID associated with the record. */
    private _contextId?;
    /** Descriptor detailing the record's schema, format, and other metadata. */
    private _descriptor;
    /** Encryption details for the record, if the data is encrypted. */
    private _encryption?;
    /** Initial state of the record before any updates. */
    private _initialWrite;
    /** Flag indicating if the initial write has been stored, to prevent duplicates. */
    private _initialWriteStored;
    /** Flag indicating if the initial write has been signed by the owner. */
    private _initialWriteSigned;
    /** Unique identifier of the record. */
    private readonly _recordId;
    /** Role under which the record is written. */
    private _protocolRole?;
    /** Cached reconstructed raw message, invalidated when record state changes. */
    private _rawMessageCache?;
    /** Dirty flag indicating the cached raw message needs to be rebuilt. */
    private _rawMessageDirty;
    /** The `RecordsWriteMessage` descriptor unless the record is in a deleted state */
    private get _recordsWriteDescriptor();
    /** The `RecordsWrite` descriptor from the current record or the initial write if the record is in a delete state. */
    private get _immutableProperties();
    /** Record's ID */
    get id(): string;
    /** Record's context ID. If the record is deleted, the context Id comes from the initial write */
    get contextId(): string | undefined;
    /** Record's creation date */
    get dateCreated(): string;
    /** Record's parent ID */
    get parentId(): string | undefined;
    /** Record's protocol */
    get protocol(): string | undefined;
    /** Record's protocol path */
    get protocolPath(): string | undefined;
    /** Record's recipient */
    get recipient(): string | undefined;
    /** Record's schema */
    get schema(): string | undefined;
    /** Record's data format */
    get dataFormat(): string | undefined;
    /** Record's CID */
    get dataCid(): string | undefined;
    /** Record's data size */
    get dataSize(): number | undefined;
    /** Record's published date */
    get datePublished(): string | undefined;
    /** Record's published status (true/false) */
    get published(): boolean | undefined;
    /** Tags of the record */
    get tags(): DwnMessageDescriptor[DwnInterface.RecordsWrite]['tags'] | undefined;
    /** DID that is the logical author of the Record. */
    get author(): string;
    /** DID that is the original creator of the Record. */
    get creator(): string;
    /** Record's message timestamp (time of creation, most recent update, or deletion). */
    get timestamp(): string;
    /** Record's encryption */
    get encryption(): DwnMessage[DwnInterface.RecordsWrite]['encryption'];
    /** Record's authorization signature(s). */
    get authorization(): DwnMessage[DwnInterface.RecordsWrite | DwnInterface.RecordsDelete]['authorization'];
    /** Record's attestation signature. */
    get attestation(): DwnMessage[DwnInterface.RecordsWrite]['attestation'] | undefined;
    /** Role under which the author is writing the record */
    get protocolRole(): string | undefined;
    /** Record's deleted state (true/false) */
    get deleted(): boolean;
    /** Record's initial write if the record has been updated */
    get initialWrite(): RecordOptions['initialWrite'];
    /**
     * Returns a copy of the raw `RecordsWriteMessage` that was used to create the current `Record` instance.
     * The result is cached and only rebuilt when the record's state changes (via `update()` or `delete()`).
     */
    get rawMessage(): DwnMessage[DwnInterface.RecordsWrite] | DwnMessage[DwnInterface.RecordsDelete];
    constructor(agent: EnboxAgent, options: RecordOptions, permissionsApi?: PermissionsApi);
    /**
     * Returns the data of the current record.
     * If the record data is not available, it attempts to fetch the data from the DWN.
     * @returns a data stream with convenience methods such as `blob()`, `json()`, `text()`, and `stream()`, similar to the fetch API response
     * @throws `Error` if the record has already been deleted.
     *
     * @beta
     */
    get data(): RecordData;
    /**
     * Stores the current record state as well as any initial write to the owner's DWN.
     *
     * @param importRecord - if true, the record will signed by the owner before storing it to the owner's DWN. Defaults to false.
     * @returns the status of the store request
     *
     * @beta
     */
    store(importRecord?: boolean): Promise<DwnResponseStatus>;
    /**
     * Signs the current record state as well as any initial write and optionally stores it to the owner's DWN.
     * This is useful when importing a record that was signed by someone else into your own DWN.
     *
     * @param store - if true, the record will be stored to the owner's DWN after signing. Defaults to true.
     * @returns the status of the import request
     *
     * @beta
     */
    import(store?: boolean): Promise<DwnResponseStatus>;
    /**
     * Send the current record to a remote DWN by specifying their DID.
     * If no DID is specified, the target is assumed to be the owner (connectedDID).
     *
     * If the record is in a deleted state, a `RecordsDelete` message is sent
     * so the remote DWN reflects the deletion.
     *
     * If an initial write is present and the Record class send cache has no
     * awareness of it, the initial write is sent first (vs waiting for the
     * regular DWN sync).
     *
     * @param target - the optional DID to send the record to, if none is set it is sent to the connectedDid
     * @returns the status of the send record request
     *
     * @beta
     */
    send(target?: string): Promise<DwnResponseStatus>;
    /**
     * Returns a JSON representation of the Record instance.
     * It's called by `JSON.stringify(...)` automatically.
     */
    toJSON(): RecordModel;
    /**
     * Convenience method to return the string representation of the Record instance.
     * Called automatically in string concatenation, String() type conversion, and template literals.
     */
    toString(): string;
    /**
     * Returns a pagination cursor for the current record given a sort order.
     *
     * @param sort the sort order to use for the pagination cursor.
     * @returns A promise that resolves to a pagination cursor for the current record.
     */
    paginationCursor(sort: DwnDateSort): Promise<DwnPaginationCursor | undefined>;
    /**
     * Update the current record on the DWN.
     *
     * On success, **both** a new `Record` instance is returned *and* the
     * current instance (`this`) is mutated in-place to reflect the updated
     * state. This means callers can safely continue using the original
     * reference after an update without capturing the returned record.
     *
     * @param params - Parameters to update the record.
     * @returns the status of the update request and the updated Record
     * @throws `Error` if the record has already been deleted.
     *
     * @beta
     */
    update({ timestamp, data, encryption, protocolRole, store, ...params }: RecordUpdateParams): Promise<RecordUpdateResult>;
    /**
     * Delete the current record on the DWN.
     *
     * On success, **both** a new `Record` instance is returned *and* the
     * current instance (`this`) is mutated in-place to reflect the deleted
     * state (the {@link Record.deleted | deleted} getter will return `true`).
     *
     * @param params - Parameters to delete the record.
     * @returns the status and a new Record instance reflecting the deleted state
     */
    delete(deleteParams?: RecordDeleteParams): Promise<RecordDeleteResult>;
    /**
     * Process the initial write, if it hasn't already been processed, with the options set for storing and/or signing as the owner.
     */
    private processInitialWriteIfNeeded;
    /**
     * Handles the various conditions around there being an initial write, whether to store initial/current state,
     * and whether to add an owner signature to the initial write to enable storage when protocol rules require it.
     */
    private processRecord;
    /**
     * Fetches the record's data from the specified DWN.
     *
     * This private method is called when the record data is not available in-memory
     * and needs to be fetched from either a local or a remote DWN.
     * It makes a read request to the specified DWN and processes the response to provide
     * a Web `ReadableStream` of the record's data.
     *
     * @param params - Parameters for fetching the record's data.
     * @param params.target - The DID of the DWN to fetch the data from.
     * @param params.isRemote - Indicates whether the target DWN is a remote node.
     * @returns A Promise that resolves to a Web `ReadableStream` of the record's data.
     * @throws If there is an error while fetching or processing the data from the DWN.
     *
     * @beta
     */
    private readRecordData;
    /**
     * If the record is operating as a delegate, fetches the appropriate permission grant
     * and applies it to the given DWN request options. This centralises the repeated
     * pattern of looking up a delegated grant and attaching it to a request.
     *
     * @param requestOptions - The DWN request options to augment with the delegate grant.
     */
    private applyDelegateGrant;
    /**
     * Verifies if the properties to be mutated are mutable.
     *
     * This private method is used to ensure that only mutable properties of the `Record` instance
     * are being changed. It checks whether the properties specified for mutation are among the
     * set of properties that are allowed to be modified. If any of the properties to be mutated
     * are not in the set of mutable properties, the method throws an error.
     *
     * @param propertiesToMutate - An iterable of property names that are intended to be mutated.
     * @param mutableDescriptorProperties - A set of property names that are allowed to be mutated.
     *
     * @throws If any of the properties in `propertiesToMutate` are not in `mutableDescriptorProperties`.
     *
     * @beta
     */
    private static verifyPermittedMutation;
    /**
     * Checks if the descriptor is a RecordsDelete descriptor.
     *
     * @param descriptor a RecordsWrite or RecordsDelete descriptor
     */
    private isRecordsDeleteDescriptor;
}
//# sourceMappingURL=record.d.ts.map