import { IKosContainerModel } from '../core/kosModel';
import { IKosModelContainer } from '../core/kos-container-model';

interface Identifiable {
    id: string;
}
/**
 * Function that transforms an entity, typically to update its id property before container insertion.
 * Useful for normalizing ids or adding prefixes/suffixes.
 */
export type IdMapper = <D extends Identifiable = Identifiable>(entity: D) => D;
type Container = IKosContainerModel<any, any> | IKosModelContainer<any>;
/**
 * Parameters for resolving container deltas.
 * @template T - The container type
 * @template D - The entity type with an id property
 */
interface ResolveParams<T extends Container, D> {
    /** The container to synchronize */
    container: T;
    /** Callback to create a new item when an entity is added */
    onAddItem: (entity: D) => any;
    /** Optional callback when an item is removed, receives the id to remove */
    onRemoveItem?: (id: string) => any;
    /** Optional callback when an existing item needs updating */
    onUpdateItem?: (entity: D, existingModel: any) => any;
    /** Optional mapper to transform entity ids before processing */
    idMapper?: IdMapper;
}
/**
 * Creates a function that synchronizes a container with a new list of entities.
 * Handles additions, removals, and optional updates to keep the container in sync.
 *
 * @template T - Container type implementing IKosModelContainer
 * @template D - Entity type with an id property
 * @param params - Configuration for resolving deltas
 * @returns A function that accepts entities and synchronizes the container
 *
 * @example
 * const syncUsers = resolveContainerDeltas({
 *   container: userContainer,
 *   onAddItem: (user) => User.instance(user.id).options(user).build(),
 *   onUpdateItem: (user, existing) => existing.update(user),
 *   onRemoveItem: (id) => id
 * });
 * syncUsers(newUserList);
 */
export declare const resolveContainerDeltas: <T extends IKosModelContainer<any>, D extends Identifiable>({ container, onAddItem, onUpdateItem, onRemoveItem, idMapper, }: ResolveParams<T, D>) => (entities: D[]) => void;
/**
 * Creates a function that synchronizes a container model's list with new entities.
 * Simpler alternative to resolveContainerDeltas that directly invokes callbacks for each addition and removal.
 *
 * @template T - Container model type implementing IKosContainerModel
 * @template D - Entity type with an id property
 * @param params - Configuration for resolving deltas
 * @returns A function that accepts entities and synchronizes by invoking callbacks
 *
 * @example
 * const syncLayers = resolveListDeltas({
 *   container: layerContainer,
 *   onAddItem: (layer) => addLayer(layer),
 *   onRemoveItem: (id) => removeLayer(id)
 * });
 * syncLayers(newLayerList);
 */
export declare const resolveListDeltas: <T extends IKosContainerModel<any, any>, D extends Identifiable>({ container, onAddItem, onRemoveItem, idMapper, }: ResolveParams<T, D>) => (entities: D[]) => void;
/**
 * Parameters for resolving deltas on plain item arrays (not container models).
 * @template T - Current item type with an id property
 * @template D - New entity type with an id property
 */
interface ResolveItemsParams<T extends Identifiable, D> {
    /** The current array of items to synchronize */
    items: T[];
    /** Callback invoked for each entity to add */
    onAddItem: (entity: D) => void;
    /** Callback invoked for each id to remove */
    onRemoveItem: (id: string) => void;
    /** Optional mapper to transform entity ids before processing */
    idMapper?: IdMapper;
}
/**
 * Creates a function that synchronizes a plain array of items with new entities.
 * Does not require a container model - works with any array of identifiable items.
 *
 * @template T - Current item type with an id property
 * @template D - New entity type with an id property
 * @param params - Configuration including the items array and callbacks
 * @returns A function that accepts entities and synchronizes the array
 *
 * @example
 * const currentItems = [{ id: '1', name: 'Item 1' }];
 * const syncItems = resolveItemListDeltas({
 *   items: currentItems,
 *   onAddItem: (item) => currentItems.push(item),
 *   onRemoveItem: (id) => {
 *     const index = currentItems.findIndex(i => i.id === id);
 *     if (index >= 0) currentItems.splice(index, 1);
 *   }
 * });
 * syncItems(newItems);
 */
export declare const resolveItemListDeltas: <T extends Identifiable, D extends Identifiable>({ items, onAddItem, onRemoveItem, idMapper, }: ResolveItemsParams<T, D>) => (entities: D[]) => void;
/**
 * Removes a prefix from an id string if present.
 * Useful for normalizing ids that may have parent or namespace prefixes.
 *
 * @param id - The id string to process
 * @param prefix - The prefix to remove (defaults to "parent-")
 * @returns The id with the prefix removed, or the original id if prefix not found
 *
 * @example
 * processId("parent-123") // returns "123"
 * processId("parent-abc", "parent-") // returns "abc"
 * processId("child-456", "parent-") // returns "child-456"
 */
export declare const processId: (id: string, prefix?: string) => string;
export {};
//# sourceMappingURL=container-utils.d.ts.map