import { AdaptableState } from '../AdaptableState/AdaptableState';
import { AdaptableApi } from '../Api/AdaptableApi';
/**
 * Options related to Adaptable State hydration / dehydration; allows users to intercept state persistence and loading with custom functionality
 */
export interface StateOptions {
    /**
     * Retrieves saved Adaptable State from storage or external source
     * @returns Promise resolving to the retrieved state object
     */
    loadState?: AdaptableLoadStateFunction;
    /**
     * Handles the actual storage of state to localStorage, server, etc. Called after `saveState()` to store the prepared state.
     * @returns Promise resolving once persistence is complete
     */
    persistState?: AdaptablePersistStateFunction;
    /**
     * Transforms state before applying it to the application. Called after `loadState()` but before the state is used.
     * @returns The transformed state object
     */
    applyState?: AdaptableApplyStateFunction;
    /**
     * Transforms state before saving to storage. Called before `persistState()`.
     * @returns The modified state ready for persistence
     */
    saveState?: AdaptableSaveStateFunction;
    /**
     * Allows clearing of remote Adaptable State. Only invoked during `StateApi.reloadInitialState()` operations.
     *
     * @defaultValue undefined
     */
    clearState?: AdaptableClearStateFunction;
    /**
     * Delay (in ms) to debounce `saveState` / `persistState` calls enabling grouping multiple sequential calls in single one (e.g. elevator doors)
     *
     * **Defaults to: 400**. Also, the wait will be max 1000ms, at which point the save/persist calls will happen anyway.
     *
     * @defaultValue 400
     */
    debounceStateDelay?: number;
    /**
     * Automatically migrate State from previous AdapTable version to current one
     *
     * @defaultValue true
     */
    autoMigrateState?: boolean;
}
/**
 * State Function Config object passed into all State Options functions
 */
export interface AdaptableStateFunctionConfig {
    /**
     * Id of current Adaptable instance
     */
    adaptableId: string;
    /**
     * State Key being used
     */
    adaptableStateKey: string;
    /**
     * current Adaptable user
     */
    userName: string;
    /**
     * Custom application Context provided in `AdaptableOptions.adaptableContext`
     */
    adaptableContext: any;
    /**
     * Adaptable API
     */
    adaptableApi: AdaptableApi;
    /**
     * Name of the action that triggered the state change.
     */
    actionName?: string;
    /**
     * Previous state before the action was applied.
     * This is useful for comparing changes or reverting if necessary.
     */
    previousState?: AdaptableState;
}
/**
 * Function that handles persisting state to storage systems (localStorage, server, etc.).
 * Called after `saveState()` to store the prepared state.
 *
 * @example
 * ```
 * persistState = (state, stateFunctionConfig) => {
 *  localStorage.setItem(stateFunctionConfig.adaptableStateKey, JSON.stringify(state))
 * }
 * ```
 *
 * @param state The state to be persisted
 * @param adaptableStateFunctionConfig Configuration details for the current Adaptable instance
 * @returns Promise resolving once persistence is complete
 */
export interface AdaptablePersistStateFunction {
    (state: any, adaptableStateFunctionConfig: AdaptableStateFunctionConfig): Promise<any>;
}
/**
 * Function that clears persisted state from the storage system.
 * Only invoked during `StateApi.reloadInitialState()` operations.
 */
export interface AdaptableClearStateFunction {
    (adaptableStateFunctionConfig: AdaptableStateFunctionConfig): Promise<any>;
}
/**
 * Function that transforms state before persistence. Called first in the persistence flow, before `persistState()`.
 *
 * @param state The Adaptable state to transform before saving
 * @param adaptableStateFunctionConfig Configuration details for the current Adaptable instance
 * @returns The modified state ready for persistence
 */
export interface AdaptableSaveStateFunction {
    (state: AdaptableState, adaptableStateFunctionConfig: AdaptableStateFunctionConfig): any;
}
/**
 * Function that retrieves Adaptable state from storage or external source. Called during initialization to hydrate the application state.
 *
 * @param config Configuration details for the current Adaptable instance
 * @returns Promise resolving to the retrieved state object
 */
export interface AdaptableLoadStateFunction {
    (config: AdaptableStateFunctionConfig): Promise<any>;
}
/**
 * Function that applies the loaded state to the application. Called after `loadState()` but before the state is used.
 * This allows for any necessary transformations or adjustments before the state is applied.
 * @param state The loaded state to transform
 * @param adaptableStateFunctionConfig Configuration details for the current Adaptable instance
 *
 * @returns The transformed state object
 */
export interface AdaptableApplyStateFunction {
    (state: any, adaptableStateFunctionConfig: AdaptableStateFunctionConfig): any;
}
