import { IThing, Thing } from '../../models/Thing.js';
import { IDataAssociation, DataAssociation, AssociationTarget } from './DataAssociation.js';
import { IDataEntity, DataEntity } from './DataEntity.js';
import { IDataModel, DataModel } from './DataModel.js';
import { IDataProperty, DataProperty } from './DataProperty.js';
import { DataNamespaceKind, DataModelKind } from '../../models/kinds.js';
import type { DataDomainRemoveOptions } from '../types.js';
/**
 * @deprecated
 */
type ItemKind = typeof DataNamespaceKind | typeof DataModelKind;
/**
 * @deprecated
 */
export interface DataItemAdaptingOptions {
    /**
     * The index at which to adapt the item.
     */
    index?: number;
}
/**
 * @deprecated
 */
interface IDataDefinitions {
    models?: IDataModel[];
    entities?: IDataEntity[];
    properties?: IDataProperty[];
    associations?: IDataAssociation[];
    namespaces?: IDataNamespace[];
    tags?: string[];
    /**
     * The list of foreign namespaces associated with this namespace.
     */
    foreign?: ForeignNamespace[];
}
/**
 * @deprecated
 */
interface DataDefinitions {
    models: DataModel[];
    entities: DataEntity[];
    properties: DataProperty[];
    associations: DataAssociation[];
    namespaces: DataNamespace[];
    /**
     * Common for the entire root namespace tags.
     * These are kept separately so the UI can generate autocomplete for tags.
     */
    tags: string[];
    /**
     * The list of foreign namespaces associated with this namespace.
     */
    foreign?: ForeignNamespace[];
}
/**
 * Data definition for a foreign namespace.
 * Each foreign namespace is resolved to a specific version.
 * This makes sure that the local data are always referencing an existing
 * entity as breaking changes should be resolved when upgrading a version.
 * @deprecated
 */
interface ForeignNamespace {
    key: string;
    version: string;
}
/**
 * Data namespace is a logical description of the hierarchy in the data.
 * @deprecated
 */
export interface IDataNamespace {
    kind: typeof DataNamespaceKind;
    /**
     * The key of the namespace.
     */
    key: string;
    /**
     * The ordered list of items in this namespace.
     */
    items: IDataItem[];
    /**
     * The data namespace description.
     */
    info: IThing;
    /**
     * The list of definitions used in the namespace.
     */
    definitions: IDataDefinitions;
}
/**
 * Data item is a reference to an object in the top namespace definitions
 * to the namespace items.
 * @deprecated
 */
export interface IDataItem {
    /**
     * The kind of the item.
     */
    kind: ItemKind;
    /**
     * The identifier in the `definitions` array of the namespace.
     */
    key: string;
}
/**
 * @deprecated
 */
export declare class DataItem implements IDataItem {
    kind: ItemKind;
    key: string;
    /**
     * A reference to the top level namespace.
     */
    private root;
    static isDataItem(input: unknown): boolean;
    static dataNamespace(root: DataNamespace, key: string): DataItem;
    static dataModel(root: DataNamespace, key: string): DataItem;
    /**
     * @param root The top-most data namespace.
     * @param input The project item definition used to restore the state.
     */
    constructor(root: DataNamespace, input: string | IDataItem);
    new(init: IDataItem): void;
    toJSON(): IDataItem;
    getItem(): DataNamespace | DataModel | undefined;
}
/**
 * Data namespace is a logical description of the hierarchy in the data.
 * @deprecated
 */
export declare class DataNamespace {
    kind: string;
    key: string;
    /**
     * The ordered list of items in this namespace.
     */
    items: DataItem[];
    /**
     * The description of the data namespace.
     */
    info: Thing;
    /**
     * When a namespace is a sub-namespace this is the reference to the
     * root namespace with all definitions.
     */
    root?: DataNamespace;
    /**
     * The list of definitions used in the namespace.
     */
    definitions: DataDefinitions;
    /**
     * The list of foreign namespaces.
     * This is used to find entities from foreign namespaces.
     * Values here are treated as read only (objects can be frozen).
     *
     * This should be set by the application and the namespace will do
     * nothing to populate this value.
     */
    foreign: DataNamespace[];
    /**
     * Creates a new data namespace from a name.
     * @param name The name to set.
     */
    static fromName(name: string, root?: DataNamespace): DataNamespace;
    /**
     * @deprecated
     */
    static definitions(): DataDefinitions;
    constructor(input?: string | IDataNamespace, root?: DataNamespace);
    new(init: IDataNamespace): void;
    toJSON(): IDataNamespace;
    /**
     * @deprecated Use the `getParentInstance()` method instead.
     */
    getParent(): DataNamespace | undefined;
    /**
     * @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.
     */
    getParentInstance(): DataNamespace | undefined;
    /**
     * Lists namespaces that are in this namespace items.
     */
    listNamespaces(): DataNamespace[];
    /**
     * Lists namespaces that are in this namespace items.
     */
    listDataModels(): DataModel[];
    /**
     * @returns The root of the namespaces tree. It might be the same object.
     */
    getRoot(): DataNamespace;
    /**
     * Removes self from the parent namespace with all data models.
     * This does noting for the root namespace.
     */
    remove(opts?: DataDomainRemoveOptions): void;
    /**
     * Checks if this is the root namespace.
     * @returns True if this is the root namespace.
     */
    isRoot(): boolean;
    /**
     * Finds a parent namespace for the given namespace.
     * @param key The namespace key to find the parent for.
     * @returns The parent namespace or undefined when the namespace does not exist. It may return the root namespace.
     */
    findParent(key: string): DataNamespace | undefined;
    /**
     * Adds a data namespace to the structure.
     * @param init The name of the namespace to add, namespace's schema, or instance.
     * @param parent The optional key of the parent namespace to add the new namespace to.
     */
    addNamespace(init: string | IDataNamespace | DataNamespace, parent?: string): DataNamespace;
    /**
     * Adapts an existing namespace to this namespace.
     * This will remove the namespace from the parent namespace and add it to this one.
     *
     * @param ns The namespace to adapt.
     * @param opts Adapting options.
     */
    adaptNamespace(ns: DataNamespace, opts?: DataItemAdaptingOptions): void;
    /**
     * Adapts an existing data model to this namespace.
     * This will remove the data model from the parent namespace and add it to this one.
     * @param model The data model to adapt.
     * @param opts The adapting options.
     */
    adaptDataModel(model: DataModel, opts?: DataItemAdaptingOptions): void;
    /**
     * Finds a namespace in the definitions.
     * @param key The key of the namespace to find.
     * @returns The namespace definition or undefined when not found.
     */
    findNamespace(key: string): DataNamespace | undefined;
    /**
     * Finds a namespace and calls the `remove()` on it.
     * @param key The key of the namespace to find.
     */
    removeNamespace(key: string, opts?: DataDomainRemoveOptions): void;
    /**
     * Adds a data model to a namespace.
     * @param init The name of the data model to add, data model's schema, or its instance.
     * @param parent The optional key of the parent namespace to add the new data model to.
     */
    addDataModel(init: string | IDataModel | DataModel, parent?: string): DataModel;
    /**
     * Finds a data model in the definitions.
     * @param key The key of the data model to find.
     * @returns The data model definition or undefined when not found.
     */
    findDataModel(key: string): DataModel | undefined;
    /**
     * A convenience function to remove an object from the namespace.
     * @param key The key of the object to remove.
     * @param kind The kind of the object to remove.
     * @param opts The options for the removal.
     * @throws Error when the kind is not known.
     */
    removeObject(key: string, kind: string, opts?: DataDomainRemoveOptions): void;
    /**
     * Finds a data model and calls the `remove()` on it.
     * @param key The key of the data model to find.
     */
    removeDataModel(key: string, opts?: DataDomainRemoveOptions): void;
    /**
     * @returns The graph of associations where keys are the source
     * entities and the value is the list of all target entities.
     */
    associationGraph(): Record<string, string[]>;
    /**
     * Prints out all associations from one entity to another through all entities that may be in between.
     *
     * @param from The key of the from entity
     * @param to The key of the target entity
     * @param g The graph generated with `associationGraph()`
     * @param path The current list of entity ids. Do not set this, it is for the recursive processing of the graph.
     * @param visited The list of visited paths to avoid cycles.
     *  Do not set this, it is for the recursive processing of the graph.
     */
    associationPath(from: string, to: string, g: Record<string, string[]>, path?: string[], visited?: Set<string>): Generator<string[]>;
    /**
     * Scans all associations for foreign namespaces and returns
     * the list of all namespaces used in the association graph.
     * This will never add this namespace's key.
     *
     * This function should be used to read keys for all related
     * namespaces through associations.
     *
     * @returns All keys of foreign namespaces.
     */
    computeForeignNamespaceKeys(): string[];
    /**
     * Finds an entity in this namespace.
     * @param key The key of the entity to find.
     */
    findEntity(key: string): DataEntity | undefined;
    /**
     * Finds a property by its key.
     * @param key The key of the property to find
     * @returns The property or undefined if not found.
     */
    findProperty(key: string): DataProperty | undefined;
    /**
     * Finds an association by its key.
     * @param key The key of the property to find
     * @returns The property or undefined if not found.
     */
    findAssociation(key: string): DataAssociation | undefined;
    /**
     * Searches for entities for association targets.
     * This is a helper function to discover entities in the current and foreign namespaces.
     *
     * @param targets The list of targets
     * @returns A list of entities. An `undefined` is put at the index where an entity cannot be found
     */
    findAssociatedEntities(targets: AssociationTarget[]): (DataEntity | undefined)[];
    /**
     * Finds an associated entity in the current or foreign namespace.
     * This is a helper function to discover entities in the current and foreign namespaces.
     *
     * @param key The key of the entity to find.
     * @param namespace The optional namespace to search in.
     * If not set, the current namespace is used.
     * This is used to find entities in foreign namespaces.
     * @returns The entity or undefined if not found.
     */
    findAssociatedEntity(key: string, namespace?: string): DataEntity | undefined;
    addForeign(ns: DataNamespace): void;
    removeForeign(ns: DataNamespace): void;
    hasForeignNamespace(key: string): boolean;
    /**
     * Checks whether the namespace is a child of the given namespace.
     * The relationship doesn't have to be direct, as long as the namespace is in the hierarchy it will return true.
     *
     * @param key The key of the parent namespace to check.
     * @returns True if this namespace is a child of the given namespace.
     */
    isChildOf(key: string): boolean;
}
export {};
//# sourceMappingURL=DataNamespace.d.ts.map