import { AnyEvent, Events } from '../coreUtils/events';
import { Translation } from '../coreUtils/i18n';
import { ElementIri, ElementModel, ElementTypeIri, LinkModel, LinkTypeIri, PropertyTypeIri } from '../data/model';
import { DataProvider } from '../data/provider';
import * as Rdf from '../data/rdf/rdfModel';
import { FormattedProperty } from '../diagram/customization';
import { Link } from '../diagram/elements';
import { Command } from '../diagram/history';
import { DiagramModel, DiagramModelEvents, DiagramModelOptions, GraphStructure, LocaleFormatter } from '../diagram/model';
import { EntityElement, EntityGroup, RelationLink, RelationGroup, ElementType, ElementTypeEvents, PropertyType, PropertyTypeEvents, LinkType, LinkTypeEvents } from './dataElements';
import { ChangeOperationsEvent, FetchOperation, FetchOperationTargetType, FetchOperationTypeToTarget } from './dataFetcher';
import { SerializedDiagram } from './serializedDiagram';
/**
 * Event data for {@link DataDiagramModel} events.
 *
 * @see {@link DataDiagramModel}
 */
export interface DataDiagramModelEvents extends DiagramModelEvents {
    /**
     * Triggered on any event from an element type in the graph.
     */
    elementTypeEvent: AnyEvent<ElementTypeEvents>;
    /**
     * Triggered on any event from a link type in the graph.
     */
    linkTypeEvent: AnyEvent<LinkTypeEvents>;
    /**
     * Triggered on any event from a property type in the graph.
     */
    propertyTypeEvent: AnyEvent<PropertyTypeEvents>;
    /**
     * Triggered on start of the diagram "create new" or "import" operations.
     *
     * @see {@link DataDiagramModel.createNewDiagram}
     * @see {@link DataDiagramModel.importLayout}
     */
    loadingStart: {
        readonly source: DataDiagramModel;
    };
    /**
     * Triggered on successful completion of diagram loading operation.
     */
    loadingSuccess: {
        readonly source: DataDiagramModel;
    };
    /**
     * Triggered on failed completion of diagram loading operation.
     */
    loadingError: {
        readonly source: DataDiagramModel;
        readonly error: unknown;
    };
    /**
     * Triggered on {@link DataDiagramModel.operations} property change.
     */
    changeOperations: ChangeOperationsEvent;
    /**
     * Triggered when a link would be created on the diagram from a data provider.
     *
     * It is possible to discard the link and avoid creating it by calling  `cancel()`
     * method on the event object.
     *
     * This event is triggered only when a link is created from a data provider and
     * won't be triggered on explicit call for the model to create links.
     */
    createLoadedLink: {
        readonly source: DataDiagramModel;
        readonly model: LinkModel;
        cancel(): void;
    };
}
/**
 * Provides entity graph content: elements and connected links,
 * as well as element, link and property types.
 *
 * @category Core
 */
export interface DataGraphStructure extends GraphStructure {
    /**
     * Gets an element type by its {@link ElementType.id} in the graph if exists.
     *
     * Element types are added to the graph as requested by
     * {@link DataDiagramModel.createElementType} so the data (e.g. labels) can be
     * fetched from a data provider.
     *
     * @see {@link DataDiagramModel.createElementType}
     */
    getElementType(elementTypeIri: ElementTypeIri): ElementType | undefined;
    /**
     * Gets an link type by its {@link LinkType.id} in the graph if exists.
     *
     * Link types are added to the graph as requested by {@link DataDiagramModel.createLinkType}
     * so the data (e.g. labels) can be fetched from a data provider.
     *
     * @see {@link DataDiagramModel.createLinkType}
     */
    getLinkType(linkTypeIri: LinkTypeIri): LinkType | undefined;
    /**
     * Gets an property type by its {@link PropertyType.id} in the graph if exists.
     *
     * Property types are added to the graph as requested by
     * {@link DataDiagramModel.createPropertyType} so the data (e.g. labels) can be
     * fetched from a data provider.
     *
     * @see {@link DataDiagramModel.createPropertyType}
     */
    getPropertyType(propertyTypeIri: PropertyTypeIri): PropertyType | undefined;
}
/** @hidden */
export interface DataDiagramModelOptions extends DiagramModelOptions {
}
/**
 * Asynchronously fetches and stores the entity diagram content:
 * graph elements and links, as well as element, link and property types;
 * maintains selection and the current language to display the data.
 *
 * Additionally, the diagram model provides the means to undo/redo commands
 * via {@link DataDiagramModel.history history}.
 *
 * @category Core
 */
export declare class DataDiagramModel extends DiagramModel implements DataGraphStructure {
    readonly events: Events<DataDiagramModelEvents>;
    readonly locale: DataGraphLocaleFormatter;
    private dataGraph;
    private loadingScope;
    private _dataProvider;
    private fetcher;
    /** @hidden */
    constructor(options: DataDiagramModelOptions);
    protected createLocale(translation: Translation): this['locale'];
    private get extendedSource();
    /**
     * Returns the data provider that is associated with the current diagram
     * via creating new or importing an existing layout.
     *
     * This provider is used to fetch entity graph data on-demand.
     *
     * By default, it is set to {@link EmptyDataProvider} instance without any graph data.
     *
     * @see {@link createNewDiagram}
     * @see {@link importLayout}
     */
    get dataProvider(): DataProvider;
    protected getTermFactory(): Rdf.DataFactory;
    /**
     * Returns an immutable snapshot of current fetch operations.
     */
    get operations(): ReadonlyArray<FetchOperation>;
    /**
     * Returns a reason (thrown error) why latest fetch operation for specific target
     * failed, if any; otherwise returns `undefined`.
     */
    getOperationFailReason<T extends FetchOperationTargetType>(type: T, target: FetchOperationTypeToTarget[T]): unknown;
    protected resetGraph(): void;
    protected subscribeGraph(): void;
    private setDataProvider;
    /**
     * Clears up the diagram and associates a new data provider for it.
     *
     * This method discards all current diagram state (elements, links and other data)
     * and resets the command history.
     *
     * @see {@link importLayout}
     */
    createNewDiagram(params: {
        /**
         * Data provider to associate with the diagram.
         *
         * This provider will be used to fetch entity graph data on-demand
         * for the diagram.
         */
        dataProvider: DataProvider;
        /**
         * Cancellation signal.
         */
        signal?: AbortSignal;
    }): Promise<void>;
    /**
     * Restores diagram content from previously exported state and associates
     * a new data provider for the diagram.
     *
     * This method discards all current diagram state (elements, links and other data)
     * and resets the command history.
     *
     * @see {@link createNewDiagram}
     * @see {@link exportLayout}
     */
    importLayout(params: {
        /**
         * Data provider to associate with the diagram.
         *
         * This provider will be used to fetch entity graph data on-demand
         * for the diagram.
         */
        dataProvider: DataProvider;
        /**
         * Diagram state to restore (elements and their positions,
         * links with visibility settings, etc).
         *
         * If specified, current diagram content will be replaced by one
         * from the state, otherwise the diagram will be cleared up only.
         */
        diagram?: SerializedDiagram;
        /**
         * Pre-cached data for the elements which should be used instead of
         * being requested from the data provider on import.
         */
        preloadedElements?: ReadonlyMap<ElementIri, ElementModel>;
        /**
         * Whether links for the between imported elements should be requested
         * from the data provider on import.
         *
         * @default false
         */
        validateLinks?: boolean;
        /**
         * Whether to fetch known link types on import and automatically hide
         * all unused link types.
         *
         * @default false
         */
        hideUnusedLinkTypes?: boolean;
        /**
         * Cancellation signal.
         */
        signal?: AbortSignal;
    }): Promise<void>;
    /**
     * Discards all diagram content and resets associated data provider to en empty one.
     */
    discardLayout(): void;
    /**
     * Exports current diagram state to a serializable object.
     *
     * The exported state includes element and link geometry, template state,
     * references to described entities and relations (via IRIs).
     * Additionally, link type visibility settings are exported as well.
     *
     * @see {@link importLayout}
     */
    exportLayout(): SerializedDiagram;
    private initLinkTypes;
    private setLinkSettings;
    private createGraphElements;
    private hideUnusedLinkTypes;
    /**
     * Requests to fetch the data for the specified elements from a data provider.
     */
    requestElementData(elementIris: ReadonlyArray<ElementIri>): Promise<void>;
    /**
     * Requests to fetch links between all elements on the diagram from a data provider.
     */
    requestLinks(options?: RequestLinksOptions): Promise<void>;
    /**
     * @deprecated Use {@link DataDiagramModel.requestLinks} instead.
     */
    requestLinksOfType(linkTypeIds?: ReadonlyArray<LinkTypeIri>): Promise<void>;
    /**
     * Creates or gets an existing entity element on the diagram.
     *
     * If element is specified as an IRI only, then the placeholder data will
     * be used.
     *
     * If multiple entity elements with the same IRI is on the diagram,
     * the first one in the order will be returned.
     *
     * The operation puts a command to the {@link DiagramModel.history command history}.
     */
    createElement(elementIriOrModel: ElementIri | ElementModel): EntityElement;
    addLink(link: Link): void;
    private onLinkInfoLoaded;
    /**
     * Creates or gets an existing links for the specified link model.
     *
     * Multiple links may exists for the same link model because in some cases
     * there could be multiple source or target elements with the same IRI.
     *
     * Each existing link for the same link model will be updated with the specified data,
     * link state property `urn:reactodia:layoutOnly` ({@link TemplateProperties.LayoutOnly})
     * will be discarded if set.
     *
     * The operation puts a command to the {@link DiagramModel.history command history}.
     */
    createLinks(data: LinkModel): Array<RelationLink | RelationGroup>;
    private createRelation;
    getElementType(elementTypeIri: ElementTypeIri): ElementType | undefined;
    /**
     * Creates or gets an existing element type in the graph.
     *
     * If element type does not exists in the graph yet, it will be created
     * and the data for it will be requested for it from the data provider.
     */
    createElementType(elementTypeIri: ElementTypeIri): ElementType;
    getLinkType(linkTypeIri: LinkTypeIri): LinkType | undefined;
    /**
     * Creates or gets an existing link type in the graph.
     *
     * If link type does not exists in the graph yet, it will be created
     * and the data for it will be requested for it from the data provider.
     */
    createLinkType(linkTypeIri: LinkTypeIri): LinkType;
    getPropertyType(propertyTypeIri: PropertyTypeIri): PropertyType | undefined;
    /**
     * Creates or gets an existing property type in the graph.
     *
     * If property type does not exists in the graph yet, it will be created
     * and the data for it will be requested for it from the data provider.
     */
    createPropertyType(propertyIri: PropertyTypeIri): PropertyType;
    /**
     * Groups multiple entity elements into an entity group element.
     *
     * Specified entity elements are removed from the diagram and
     * a single entity group element with these entities is created
     * at the center of the bounding box between them.
     *
     * Relation links from/to specified elements are re-grouped to
     * form relation group links the same way.
     *
     * The operation puts a command to the {@link DiagramModel.history command history}.
     *
     * @see {@link ungroupAll}
     * @see {@link ungroupSome}
     */
    group(entities: ReadonlyArray<EntityElement>): EntityGroup;
    /**
     * Ungroups one or many entity group elements into all contained entity elements.
     *
     * Specified entity group elements are removed from the diagram and
     * all contained entity elements are created at the same position as
     * the owner group.
     *
     * Relation links from/to ungrouped entities are re-grouped to
     * form relation group links the same way.
     *
     * The operation puts a command to the {@link DiagramModel.history command history}.
     *
     * @see {@link group}
     * @see {@link ungroupSome}
     */
    ungroupAll(groups: ReadonlyArray<EntityGroup>): EntityElement[];
    /**
     * Ungroups some entities from an entity group element.
     *
     * Specified entity group is modified to remove target entities
     * and re-create them at the same position as the group.
     * If only one or less entities are left in the group,
     * the group will be completely ungrouped instead.
     *
     * Relation links from/to ungrouped entities are re-grouped to
     * form relation group links the same way.
     *
     * The operation puts a command to the {@link DiagramModel.history command history}.
     *
     * @see {@link group}
     * @see {@link ungroupAll}
     */
    ungroupSome(group: EntityGroup, entities: ReadonlySet<ElementIri>): EntityElement[];
    /**
     * Re-creates a set of relations or relation groups to automatically
     * group relations with the same link type connected to entity groups.
     *
     * The operation puts a command to the {@link DiagramModel.history command history}.
     */
    regroupLinks(links: ReadonlyArray<RelationLink | RelationGroup>): void;
    private recreateLinks;
}
/**
 * Options for {@link DataDiagramModel.requestLinks}.
 *
 * @see {@link DataDiagramModel.requestLinks}
 * @see {@link restoreLinksBetweenElements}
 */
export interface RequestLinksOptions {
    /**
     * If specified, skips fetching links between existing elements on the diagram
     * and only adds links between all elements and the specified set.
     *
     * It is recommended to specify this set if possible to allow incremental
     * link loading (avoid fetching already added links).
     */
    addedElements?: ReadonlyArray<ElementIri>;
    /**
     * If specified, instructs the data provider to only return links with one
     * of the specified types.
     */
    linkTypes?: ReadonlyArray<LinkTypeIri>;
}
export interface DataGraphLocaleFormatter extends LocaleFormatter {
    /**
     * Formats an array of element types into a sorted labels
     * to display in the UI.
     */
    formatElementTypes(types: ReadonlyArray<ElementTypeIri>, language?: string): string[];
    /**
     * Formats a map of property values into a sorted list with labels
     * to display in the UI.
     */
    formatPropertyList(properties: {
        readonly [id: string]: ReadonlyArray<Rdf.NamedNode | Rdf.Literal>;
    }, language?: string): FormattedProperty[];
}
/**
 * Command effect to request data for the specified entity elements on the diagram
 * from a data provider.
 *
 * @category Commands
 * @see {@link DataDiagramModel.requestElementData}
 */
export declare function requestElementData(model: DataDiagramModel, elementIris: ReadonlyArray<ElementIri>): Command;
/**
 * Command effect to request links between elements on the diagram
 * from a data provider.
 *
 * @category Commands
 * @see {@link DataDiagramModel.requestLinks}
 */
export declare function restoreLinksBetweenElements(model: DataDiagramModel, options?: RequestLinksOptions): Command;
//# sourceMappingURL=dataDiagramModel.d.ts.map