import { Activity } from "./Activity";
import { Component } from "./Component";
import { DeploymentConfig } from "./DeploymentConfig";
import { Form } from "./Form";
import { Lookup, Dictionary, Iterator, Iterable } from "../Collections";
import { Reference } from "./Reference";
import { Resource } from "./Resource";
import { Program } from "./Program";
import { Step } from "./Step";
import { Transition } from "./Transition";
/** Contains the results of the import operation. */
export interface ImportResults extends Lookup<Resource> {
    start?: Step;
}
/** Delegates remapping of identifiers and names. */
export interface NameIdMapper {
    (id: number, name: string): boolean | number | string | {
        id?: number;
        name?: string;
    };
}
/** Inspects and manipulates a Workflow program. */
export declare class ProgramInspector {
    /** Indicates the map of incidents. */
    protected incidents: IncidentList;
    /** Indicates the components being built. */
    protected components: ComponentList;
    /** Indicates the forms being built. */
    protected forms: FormList;
    /** Indicates the references being built. */
    protected references: ReferenceList;
    /** Indicates the steps being built. */
    protected steps: StepList;
    /** Indicates the transitions being built. */
    protected transitions: TransitionList;
    /** Indicates the program being built. */
    program: Program;
    /** Indicates the starting step. */
    start: Step;
    /** Yields a new identifier that is not currently in use. */
    newId(nextId?: number): number;
    /** Checks to see if the given identifier exists. */
    exists(resource: Resource | undefined): boolean;
    /** Retrieves the resource for the given identifier. */
    find(id: number): Resource;
    /** Retrieves the component for the given identifier or name. */
    findComponent(nameId: number | string): Component;
    /** Retrieves the form for the given identifier or name. */
    findForm(nameId: number | string): Form;
    /** Retrieves the reference for the given identifier or name. */
    findReference(nameId: number | string): Reference;
    /** Retrieves the reference for the given identifier or name. */
    findStep(nameId: number | string): Step;
    /** Iterates over all the assets. */
    findTransition(nameId: number | string): Transition;
    /** Iterates over all the assets. */
    all(): Iterator<Resource>;
    /** Iterates over the components. */
    allComponents(): Iterator<Component>;
    /** Iterates over the forms. */
    allForms(): Iterator<Form>;
    /** Iterates over the references. */
    allReferences(): Iterator<Reference>;
    /** Iterates over the steps. */
    allSteps(): Iterator<Step>;
    /** Iterates over the transitions. */
    allTransitions(): Iterator<Transition>;
    /** Adds a new component. */
    addComponent(): Component;
    /** Adds a new form. */
    addForm(): Form;
    /** Adds a reference. */
    addReference(): Reference;
    /** Adds a new step. */
    addStep(): Step;
    /** Adds a new transition. */
    addTransition(source: Step, target: Step): Transition;
    /** Forms a lookup cache of the components.  */
    cacheComponents(): Lookup<Component>;
    /** Forms a lookup cache of the forms.  */
    cacheForms(): Lookup<Form>;
    /** Forms a lookup cache of the references.  */
    cacheReference(): Lookup<Reference>;
    /** Forms a lookup cache of the steps.  */
    cacheSteps(): Lookup<Step>;
    /** Forms a lookup cache of the transitions.  */
    cacheTransitions(): Lookup<Transition>;
    /** Relates components to steps and transitions. */
    relate(components: Iterable<Component>): Iterator<Activity>;
    /** Relates steps to transitions. */
    relate(steps: Iterable<Step>, branch?: boolean | number | string): Iterator<Transition>;
    /** Relates transitions to steps. */
    relate(transitions: Iterable<Transition>): Iterator<Step>;
    /** Relates resources to resources. */
    relate(member: Iterable<Resource>): Iterator<Resource>;
    /** Removes the given resource. */
    remove(resource: Resource, orphan?: boolean): boolean;
    /** Removes the given resources via an iterator. */
    remove(resources: Resource[], orphan?: boolean): number;
    /** Removes the given resources via an iterator. */
    remove(resources: Iterator<Resource>, orphan?: boolean): number;
    /** Removes the given component. */
    removeComponent(resource: Resource): boolean;
    /** Removes the given form. */
    removeForm(resource: Resource): boolean;
    /** Removes the given reference. */
    removeReference(resource: Resource): boolean;
    /** Removes the given step. */
    removeStep(resource: Resource): boolean;
    /** Removes the given transition. */
    removeTransition(resource: Resource): boolean;
    /** Renames the given component to another identifer. */
    shift(resource: Resource, id: number): void;
    /** Renames the given component to another identifer. */
    shiftComponent(resource: Resource, id: number): boolean;
    /** Shifts the given form to another identifier. */
    shiftForm(resource: Resource, id: number): boolean;
    /** Shifts the given step to another identifier. */
    shiftReference(resource: Resource, id: number): boolean;
    /** Shifts the given step to another identifier. */
    shiftStep(resource: Resource, id: number): boolean;
    /** Renames the given transition to another identifier. */
    shiftTransition(resource: Resource, id: number): boolean;
    /** Renames the given resource. */
    rename(resource: Resource, name: string): string;
    /** Renames the given componnent. */
    renameComponent(resource: Resource, name: string): boolean;
    /** Renames the given form. */
    renameForm(resource: Resource, name: string): boolean;
    /** Renames the given reference. */
    renameReference(resource: Resource, name: string): boolean;
    /** Renames the given step. */
    renameStep(resource: Resource, name: string): boolean;
    /** Renames the given transition. */
    renameTransition(resource: Resource, name: string): boolean;
    /** Changes the starting step. */
    changeStart(step: Step): boolean;
    /** Changes the branch of the given step or transition. */
    changeBranch(transition: Transition, branch: boolean | number | string): boolean;
    /** Changes the parent of the given step or transition. */
    changeParent(activity: Activity, parent: Component): boolean;
    /** Changes the source of the given transition. */
    changeSource(transition: Transition, source: Step): boolean;
    /** Changes the target of the given transition. */
    changeTarget(transition: Transition, target: Step): boolean;
    /** Tests if the given resource is a component */
    isComponent(resource: Resource | undefined): resource is Component;
    /** Tests if the given resource is a member of the component. */
    isParent(component: Component, resource: Resource): resource is Activity;
    /** Tests if the given resource is a form. */
    isForm(resource: Resource | undefined): resource is Form;
    /** Tests if the given resource is an activity. */
    isActivity(resource: Resource): resource is Activity;
    /** Tests if the given resource is a reference. */
    isReference(resource: Resource | undefined): resource is Reference;
    /** Tests if the given resource is a step. */
    isStep(resource: Resource | undefined): resource is Step;
    /** Tests if the given resource is a transition. */
    isTransition(resource: Resource | undefined): resource is Transition;
    /** Tests if the given resource is the source for the given transition. */
    isSource(transition: Transition, resource: Resource): resource is Step;
    /** Tests if the given resource is the target for the given transition. */
    isTarget(transition: Transition, resource: Resource): resource is Step;
    /** Returns deployment configuration details. */
    getDeploymentConfig(): DeploymentConfig;
    /**
     * Retrieves the default locale for the workflow.
     */
    getDefaultLocale(): string;
    /**
     * Retrieves the string lookups for the given locale.
     * @param locale The locale of the strings to retrieve. Defaults to the invariant strings.
     */
    getStrings(locale?: string): Lookup<string>;
    /** Attempts to align the underlying program with the actual state of the inspector. */
    /** Use this to get a static view of the program (say for saving a project). */
    realize(): void;
    release(): void;
    resolveStart(start?: Step | number | string): Step;
    /**
     * Imports a workflow program (must be pure JSON).
     * @param program The program as JSON or as a JSON-string.
     * @param compact Instructs the parsing to assume compact form.
     * @param mapper Indicates how identifiers and names should get preserved.
     */
    import(program: Program | string, compact?: boolean, mapper?: NameIdMapper): ImportResults;
    /** Exports the program. */
    export(): Program;
    /** Resets the entire state. */
    reset(): void;
    toJSON(): Program;
}
export interface Incident<TResource extends Resource> {
    token: string;
    master?: ResourceList<TResource, Incident<TResource>>;
    resource?: TResource;
}
export declare class IncidentList extends Dictionary<Incident<Resource>> {
    nextId: number;
    findFor(resource: Resource | undefined): Incident<Resource>;
    newId(): number;
    relate(resource: Resource, branch: string): Iterable<Resource>;
}
export declare abstract class ResourceList<T extends Resource, TIncident extends Incident<T>> extends Dictionary<TIncident> {
    incidents: IncidentList;
    protected cacheLookup: Lookup<T>;
    abstract qualify(name: string): string;
    abstract create(): T;
    constructor(incidents: IncidentList);
    all(): Iterator<T>;
    cache(): Lookup<T>;
    findFor(resource: Resource | undefined): TIncident | undefined;
    test(incident: Incident<Resource>): incident is TIncident;
    findWith(nameId: number | string): T;
    shift(incident: TIncident, id: number): void;
    shiftFor(resource: Resource | undefined, id: number): boolean;
    /**
     * Renames the specified item, returning the old name.
     * @param incident The thing to be renamed.
     * @param name The new name.
     */
    rename(incident: TIncident, name: string): string;
    renameFor(resource: Resource | undefined, name: string): boolean;
    add(): TIncident;
    removeFor(resource: Resource | undefined): boolean;
    unlink(incident: Incident<Resource>): number;
    relate(incident: Incident<Resource>, branch: string): Iterable<Resource>;
    changeParent(this: StepList | TransitionList, incident: StepIncident | TransitionIncident, parent: ComponentIncident): void;
}
export interface ComponentIncident extends Incident<Component> {
    steps?: Dictionary<StepIncident>;
    transitions?: Dictionary<TransitionIncident>;
}
export declare class ComponentList extends ResourceList<Component, ComponentIncident> {
    create(): Component;
    qualify(name: string): string;
    unlink(incident: ComponentIncident): number;
    relate(incident: ComponentIncident, branch: string): Iterable<Activity>;
}
export declare class FormList extends ResourceList<Form, Incident<Form>> {
    create(): Form;
    qualify(name: string): string;
}
export declare class ReferenceList extends ResourceList<Reference, Incident<Reference>> {
    create(): Reference;
    qualify(name: string): string;
}
export interface StepIncident extends Incident<Step> {
    master?: StepList;
    parent?: ComponentIncident;
    branches?: Lookup<Transition | Transition[]>;
    transitions?: Dictionary<TransitionIncident>;
}
export declare class StepList extends ResourceList<Step, StepIncident> {
    create(): Step;
    qualify(name: string): string;
    siblings(incident: ComponentIncident): Dictionary<StepIncident | TransitionIncident>;
    unlink(incident: StepIncident): number;
    relate(incident: StepIncident, branch: string): Iterable<Transition>;
}
export interface TransitionIncident extends Incident<Transition> {
    master?: TransitionList;
    parent?: ComponentIncident;
    source?: StepIncident;
    target?: StepIncident;
}
export declare class TransitionList extends ResourceList<Transition, TransitionIncident> {
    create(): Transition;
    qualify(name: string): string;
    siblings(incident: ComponentIncident): Dictionary<StepIncident | TransitionIncident>;
    unlink(incident: TransitionIncident): number;
    relate(incident: TransitionIncident, branch: string): Iterable<Step>;
}
export declare type LocaleParts = {
    language: string;
    script?: string;
    territory?: string;
};
/**
 * Parses a locale code into its component parts.
 * If the locale is invalid, nothing is returned.
 */
export declare function parseLocale(locale: string): LocaleParts;
/** Converts a locale code to its canonicalized form, e.g. "de-ch" becomes "de-CH", "ZH-HANS-CN" becomes "zh-Hans-CN"). */
export declare function canonicalizeLocale(locale: string): string;
