import type { UserClient as KeetaNetUserClient } from '@keetanetwork/keetanet-client';
import type { Logger } from '../../lib/log/index.ts';
import type { ServiceMetadata, ServiceMetadataAuthenticationType } from '../../lib/resolver.ts';
import type { Buffer } from '../../lib/utils/buffer.js';
import type { KeetaNetAccount, ContactsClientConfig, IconsClientConfig, StorageObjectMetadata, SearchCriteria, SearchPagination, QuotaStatus, StorageObjectVisibility, KeetaStorageAnchorDeleteClientRequest } from './common.ts';
import { getDefaultResolver } from '../../config.js';
import { StorageContactsClient } from './clients/contacts.js';
import { StorageIconsClient } from './clients/icon.js';
import Resolver from '../../lib/resolver.js';
/**
 * The configuration options for the Storage Anchor client.
 */
export type KeetaStorageAnchorClientConfig = {
    /**
     * The ID of the client. This is used to identify the client in logs.
     * If not provided, a random ID will be generated.
     */
    id?: string;
    /**
     * The logger to use for logging messages. If not provided, no logging
     * will be done.
     */
    logger?: Logger;
    /**
     * The resolver to use for resolving Storage Anchor services. If not
     * provided, a default resolver will be created using the provided
     * client and network.
     */
    resolver?: Resolver;
    /**
     * The account to use for signing requests. If not provided, the
     * account associated with the provided client will be used.
     */
    signer?: KeetaNetAccount;
    /**
     * Account to perform changes on. If not provided, the account
     * associated with the provided client will be used.
     */
    account?: KeetaNetAccount;
} & Omit<NonNullable<Parameters<typeof getDefaultResolver>[1]>, 'client'>;
/**
 * Configuration for a storage session.
 * Sessions provide a simplified API with default account, working directory, and visibility.
 */
export type SessionConfig = {
    /**
     * The account to use for all operations in this session.
     */
    account: KeetaNetAccount;
    /**
     * Optional working directory prefix for relative paths.
     * e.g., '/user/pubkey/docs/' - relative paths will be appended to this.
     */
    workingDirectory?: string;
    /**
     * Default visibility for put operations (defaults to 'private').
     */
    defaultVisibility?: StorageObjectVisibility;
};
/**
 * Configuration for storage sub-clients.
 */
export interface StorageSubClientConfig {
    session: KeetaStorageAnchorSession;
    logger?: Logger | undefined;
}
/**
 * An opaque type that represents a provider ID.
 */
type ProviderID = string;
/**
 * A list of operations that can be performed by the Storage Anchor service.
 */
type KeetaStorageAnchorOperations = {
    [operation in keyof NonNullable<ServiceMetadata['services']['storage']>[string]['operations']]?: {
        url: (params?: {
            [key: string]: string;
        }) => URL;
        options: {
            authentication: ServiceMetadataAuthenticationType;
        };
    };
};
/**
 * The service information for a Storage Anchor service.
 */
type KeetaStorageServiceInfo = {
    operations: {
        [operation in keyof KeetaStorageAnchorOperations]: Promise<KeetaStorageAnchorOperations[operation]>;
    };
    /**
     * The anchor's public key string (for converting to Account object).
     */
    anchorAccountPublicKey?: string;
};
interface KeetaStorageAnchorBaseConfig {
    client: KeetaNetUserClient;
    logger?: Logger | undefined;
}
declare class KeetaStorageAnchorBase {
    protected readonly logger?: Logger | undefined;
    protected readonly client: KeetaNetUserClient;
    constructor(config: KeetaStorageAnchorBaseConfig);
}
/**
 * A session provides a simplified API for storage operations with default account,
 * working directory, and visibility settings.
 */
export declare class KeetaStorageAnchorSession {
    #private;
    readonly provider: KeetaStorageAnchorProvider;
    readonly account: KeetaNetAccount;
    readonly workingDirectory: string;
    constructor(provider: KeetaStorageAnchorProvider, config: SessionConfig);
    /**
     * Store data at a relative path.
     * For public visibility, the anchor account is automatically fetched from the provider.
     *
     * @param relativePath - The relative path
     * @param data - The binary data to store
     * @param options.mimeType - MIME type of the data
     * @param options.tags - Optional plaintext tags
     * @param options.visibility - Object visibility
     *
     * @returns The created/updated object metadata
     */
    put(relativePath: string, data: Buffer, options: {
        mimeType: string;
        tags?: string[];
        visibility?: StorageObjectVisibility;
        additionalPrincipals?: KeetaNetAccount[];
    }): Promise<StorageObjectMetadata>;
    /**
     * Get data from a relative path.
     *
     * @param relativePath - The relative path
     *
     * @returns The decrypted data and mime-type, or null if not found
     */
    get(relativePath: string): Promise<{
        data: Buffer;
        mimeType: string;
    } | null>;
    /**
     * Get metadata for an object at a relative path.
     *
     * @param relativePath - The relative Path
     *
     * @returns The object metadata, or null if not found
     */
    getMetadata(relativePath: string): Promise<StorageObjectMetadata | null>;
    /**
     * Update metadata for an object at a relative path.
     *
     * @param relativePath - The relative path
     * @param options.tags - New tags for the object
     * @param options.visibility - New visibility setting
     *
     * @returns The updated object metadata, or null if not found
     */
    updateMetadata(relativePath: string, options: {
        tags: string[];
        visibility?: StorageObjectVisibility;
    }): Promise<StorageObjectMetadata | null>;
    /**
     * Delete data at a relative path.
     *
     * @param relativePath - The relative path
     *
     * @returns True if the object was deleted, false if it didn't exist
     */
    delete(relativePath: string): Promise<boolean>;
    /**
     * Search for objects. Owner is automatically set to the session account.
     *
     * @param criteria - Optional search criteria (owner is set automatically)
     * @param pagination - Optional pagination settings
     *
     * @returns Search results with optional nextCursor for pagination
     */
    search(criteria?: Omit<SearchCriteria, 'owner'>, pagination?: SearchPagination): Promise<{
        results: StorageObjectMetadata[];
        nextCursor?: string;
    }>;
    /**
     * Get a pre-signed public URL for a relative path.
     *
     * @param relativePath - The relative path
     * @param options.ttl - Optional TTL in seconds
     *
     * @returns The pre-signed URL for public access
     */
    getPublicUrl(relativePath: string, options?: {
        ttl?: number;
    }): Promise<string>;
}
/**
 * Represents a Storage Anchor provider for performing storage operations.
 */
export declare class KeetaStorageAnchorProvider extends KeetaStorageAnchorBase {
    #private;
    /**
     * Service information including available operations and endpoints.
     */
    readonly serviceInfo: KeetaStorageServiceInfo;
    /**
     * Unique identifier for this provider.
     */
    readonly providerID: ProviderID;
    /**
     * The anchor account for this provider.
     */
    readonly anchorAccount: KeetaNetAccount | null;
    constructor(serviceInfo: KeetaStorageServiceInfo, providerID: ProviderID, parent: KeetaStorageAnchorClient);
    /**
     * Delete an object by path.
     *
     * @param request - The delete request parameters
     * @param request.path - The storage path to delete
     * @param request.account - Optional account for signing (falls back to client account)
     *
     * @returns True if the object was deleted, false if it didn't exist
     */
    delete(request: KeetaStorageAnchorDeleteClientRequest): Promise<boolean>;
    /**
     * Get (retrieve) an object by path.
     * Data is automatically decrypted from the EncryptedContainer.
     *
     * @param options.path - The storage path (e.g., "/user/<publicKey>/myfile.txt")
     * @param options.account - Optional account for signing and decryption (falls back to client account)
     *
     * @returns The decrypted data and mime-type, or null if not found
     *
     * @throws PrivateKeyRequired if no account with private key is available
     * @throws InvalidResponse if the stored data cannot be decrypted
     */
    get(options: {
        path: string;
        account?: KeetaNetAccount;
    }): Promise<{
        data: Buffer;
        mimeType: string;
    } | null>;
    /**
     * Get metadata for an object by path.
     *
     * @param options.path - The storage path (e.g., "/user/<publicKey>/myfile.txt")
     * @param options.account - Optional account for signing (falls back to client account)
     *
     * @returns The object metadata, or null if not found
     *
     * @throws PrivateKeyRequired if no account with private key is available
     */
    getMetadata(options: {
        path: string;
        account?: KeetaNetAccount;
    }): Promise<StorageObjectMetadata | null>;
    /**
     * Update metadata for an existing object without re-uploading data.
     *
     * @param options.path - The storage path
     * @param options.tags - New tags for the object
     * @param options.visibility - New visibility setting
     * @param options.account - Optional account for signing (falls back to client account)
     *
     * @returns The updated object metadata, or null if not found
     *
     * @throws PrivateKeyRequired if no account with private key is available
     */
    updateMetadata(options: {
        path: string;
        tags: string[];
        visibility: StorageObjectVisibility;
        account?: KeetaNetAccount;
    }): Promise<StorageObjectMetadata | null>;
    /**
     * Put (create/update) an object.
     * Data is automatically wrapped in an EncryptedContainer.
     *
     * @param options.path - The storage path (e.g., "/user/<publicKey>/myfile.txt")
     * @param options.data - The binary data to store
     * @param options.mimeType - MIME type of the data (stored encrypted in the container)
     * @param options.tags - Optional plaintext tags for the object
     * @param options.visibility - Object visibility
     * @param options.account - Optional account for signing (falls back to client account)
     * @param options.anchorAccount - Anchor account for public object encryption (falls back to provider's anchor)
     *
     * @returns The created/updated object metadata
     *
     * @throws PrivateKeyRequired if no account with private key is available
     * @throws InvalidAnchorAccount if public visibility requires an anchor account that's not available
     */
    put(options: {
        path: string;
        data: Buffer;
        mimeType: string;
        tags?: string[];
        visibility?: StorageObjectVisibility;
        account?: KeetaNetAccount;
        anchorAccount?: KeetaNetAccount;
        additionalPrincipals?: KeetaNetAccount[];
    }): Promise<StorageObjectMetadata>;
    /**
     * Search for objects matching criteria.
     *
     * @param options.criteria - Search criteria
     * @param options.pagination - Optional pagination settings
     * @param options.account - Optional account for signing (falls back to client account)
     *
     * @returns Search results with optional nextCursor for pagination
     */
    search(options: {
        criteria: SearchCriteria;
        pagination?: SearchPagination;
        account?: KeetaNetAccount;
    }): Promise<{
        results: StorageObjectMetadata[];
        nextCursor?: string;
    }>;
    /**
     * Get quota status for the authenticated user.
     *
     * @param options.account - Optional account for signing (falls back to client account)
     *
     * @returns Current quota status
     */
    getQuotaStatus(options?: {
        account?: KeetaNetAccount;
    }): Promise<QuotaStatus>;
    /**
     * Generate a pre-signed URL for public access to an object.
     * The URL is signed by the owner and has a limited lifetime.
     *
     * @param options.path - The storage path to the public object
     * @param options.ttl - TTL in seconds
     * @param options.account - Owner account for signing (falls back to client account, must have private key)
     *
     * @returns The pre-signed URL for unauthenticated access
     *
     * @throws PrivateKeyRequired if no account with private key is available
     * @throws OperationNotSupported if the public endpoint is not available
     */
    getPublicUrl(options: {
        path: string;
        ttl?: number;
        account?: KeetaNetAccount;
    }): Promise<string>;
    /**
     * Create a session.
     */
    beginSession(config: SessionConfig): KeetaStorageAnchorSession;
    /**
     * Execute a function within a session scope.
     */
    withSession<T>(config: SessionConfig, fn: (session: KeetaStorageAnchorSession) => Promise<T>): Promise<T>;
    /**
     * Get a contacts client bound to the given account.
     */
    getContactsClient(config: ContactsClientConfig): StorageContactsClient;
    /**
     * Get an icons client bound to the given account.
     */
    getIconsClient(config: IconsClientConfig): StorageIconsClient;
}
declare class KeetaStorageAnchorClient extends KeetaStorageAnchorBase {
    #private;
    readonly resolver: Resolver;
    readonly id: string;
    constructor(client: KeetaNetUserClient, config?: KeetaStorageAnchorClientConfig);
    /**
     * Get all available storage providers
     */
    getProviders(): Promise<KeetaStorageAnchorProvider[] | null>;
    /**
     * Get a specific provider by ID
     */
    getProviderByID(providerID: string): Promise<KeetaStorageAnchorProvider | null>;
    /**
     * Get a contacts client bound to the given account.
     * Resolves the first available provider and constructs a StorageContactsClient.
     */
    getContactsClient(config: ContactsClientConfig): Promise<StorageContactsClient | null>;
    /**
     * Get an icons client bound to the given account.
     * Resolves the first available provider and constructs a StorageIconsClient.
     */
    getIconsClient(config: IconsClientConfig): Promise<StorageIconsClient | null>;
}
export default KeetaStorageAnchorClient;
//# sourceMappingURL=client.d.ts.map