import { URL } from 'url';

type EntityId = number;
type TypePath = string;
type BrpResponse<R> = {
    jsonrpc: string;
    id: number;
    result?: R;
    error?: BrpError;
};
type BrpError = {
    code: number;
    message: string;
    data?: BrpValue;
};
type BrpErrors = {
    [key: TypePath]: BrpError;
};
type BrpValue = string | number | boolean | null | BrpValue[] | BrpObject;
type BrpObject = {
    [key: TypePath]: BrpValue;
};
type BrpStructurePath = (TypePath | number)[];
declare class BrpStructure {
    private tree;
    constructor(tree: BrpValue);
    has(path?: BrpStructurePath): boolean;
    get(path?: BrpStructurePath): BrpValue | undefined;
    set(path: BrpStructurePath | undefined, value: BrpValue): void;
    keys(path?: BrpStructurePath): TypePath[] | number[];
    values(path?: BrpStructurePath): BrpValue[];
    private static hasBrpValue;
    private static getBrpValue;
    private static setBrpValue;
}
type BrpGetWatchResult = {
    components: BrpObject;
    removed: TypePath[];
    errors: BrpErrors;
};
type BrpGetWatchStrictResult = {
    components: BrpObject;
    removed: TypePath[];
};
type BrpListWatchResult = {
    added: TypePath[];
    removed: TypePath[];
};
declare enum ServerVersion {
    IGNORE = "IGNORE",
    V0_15 = "0.15",
    V0_16 = "0.16"
}

declare class BevyRemoteProtocol {
    static DEFAULT_URL: URL;
    static INTERNAL_TO_V0_15: Record<string, string>;
    static INTERNAL_TO_V0_16: Record<string, string>;
    static ANY_TO_INTERNAL: Record<string, string>;
    private static decoder;
    private id;
    url: URL;
    serverVersion: ServerVersion;
    constructor(url: URL, version: ServerVersion);
    private nextId;
    private translateToInternal;
    private translateToSpecificVersion;
    private requestWrapper;
    private request;
    private requestStream;
    /**
     * Retrieve the values of one or more components from an entity.
     *
     * This function passes a flag `strict` as `false` by default.
     *
     * `params`:
     * - `entity`: The ID of the entity whose components will be fetched.
     * - `components`: An array of [fully-qualified type names] of components to fetch.
     * - `strict` (optional): A flag to enable strict mode which will fail if any one of the
     *   components is not present or can not be reflected.
     *
     * `result`:
     * - `components`: A map associating each type name to its value on the requested entity.
     * - `errors`: A map associating each type name with an error if it was not on the entity
     *   or could not be reflected.
     */
    get(entity: EntityId, components: TypePath[]): Promise<BrpResponse<{
        components: BrpObject;
        errors: BrpErrors;
    }>>;
    /**
     * Retrieve the values of one or more components from an entity.
     *
     * This function passes a flag `strict` as `true` by default.
     *
     * `params`:
     * - `entity`: The ID of the entity whose components will be fetched.
     * - `components`: An array of [fully-qualified type names] of components to fetch.
     * - `strict` (optional): A flag to enable strict mode which will fail if any one of the
     *   components is not present or can not be reflected.
     *
     * `result`: A map associating each type name to its value on the requested entity.
     */
    get_strict(entity: EntityId, components: TypePath[]): Promise<BrpResponse<BrpObject>>;
    /**
     * Perform a query over components in the ECS, returning all matching entities and their associated
     * component values.
     *
     * All of the arrays that comprise this request are optional, and when they are not provided, they
     * will be treated as if they were empty.
     *
     * `params`:
     * - `components` (optional): An array of [fully-qualified type names] of components to fetch.
     * - `option` (optional): An array of fully-qualified type names of components to fetch optionally.
     * - `has` (optional): An array of fully-qualified type names of components whose presence will be
     *   reported as boolean values.
     * - `with` (optional): An array of fully-qualified type names of components that must be present
     *   on entities in order for them to be included in results.
     * - `without` (optional): An array of fully-qualified type names of components that must *not* be
     *   present on entities in order for them to be included in results.
     *
     * `result`: An array, each of which is an object containing:
     * - `entity`: The ID of a query-matching entity.
     * - `components`: A map associating each type name from `components`/`option` to its value on the matching
     *   entity if the component is present.
     * - `has`: A map associating each type name from `has` to a boolean value indicating whether or not the
     *   entity has that component. If `has` was empty or omitted, this key will be omitted in the response.
     */
    query({ components, option, has, filterWith, filterWithout, }: {
        components?: TypePath[];
        option?: TypePath[];
        has?: TypePath[];
        filterWith?: TypePath[];
        filterWithout?: TypePath[];
    }): Promise<BrpResponse<[{
        entity: EntityId;
        components: BrpObject;
        has: {
            [key: TypePath]: boolean;
        };
    }]>>;
    /**
     * Create a new entity with the provided components and return the resulting entity ID.
     *
     * `params`:
     * - `components`: A map associating each component's [fully-qualified type name] with its value.
     *
     * `result`:
     * - `entity`: The ID of the newly spawned entity.
     */
    spawn(components: BrpObject): Promise<BrpResponse<{
        entity: EntityId;
    }>>;
    /**
     * Despawn the entity with the given ID.
     *
     * `params`:
     * - `entity`: The ID of the entity to be despawned.
     *
     * `result`: null.
     */
    destroy(entity: EntityId): Promise<BrpResponse<null>>;
    /**
     * Delete one or more components from an entity.
     *
     * `params`:
     * - `entity`: The ID of the entity whose components should be removed.
     * - `components`: An array of [fully-qualified type names] of components to be removed.
     *
     * `result`: null.
     */
    remove(entity: EntityId, components: TypePath[]): Promise<BrpResponse<null>>;
    /**
     * Insert one or more components into an entity.
     *
     * `params`:
     * - `entity`: The ID of the entity to insert components into.
     * - `components`: A map associating each component's fully-qualified type name with its value.
     *
     * `result`: null.
     */
    insert(entity: EntityId, components: BrpObject): Promise<BrpResponse<null>>;
    /**
     * Assign a new parent to one or more entities.
     *
     * `params`:
     * - `entities`: An array of entity IDs of entities that will be made children of the `parent`.
     * - `parent` (optional): The entity ID of the parent to which the child entities will be assigned.
     *   If excluded, the given entities will be removed from their parents.
     *
     * `result`: null.
     */
    reparent(entities: EntityId[], parent?: EntityId): Promise<BrpResponse<null>>;
    /**
     * List all registered components or all components present on an entity.
     *
     * When `params` is not provided, this lists all registered components. If `params` is provided,
     * this lists only those components present on the provided entity.
     *
     * `params` (optional):
     * - `entity`: The ID of the entity whose components will be listed.
     *
     * `result`: An array of fully-qualified type names of components.
     */
    list(entity?: EntityId): Promise<BrpResponse<TypePath[]>>;
    /**
     * Watch the values of one or more components from an entity.
     *
     * This function passes a flag `strict` as `false` by default.
     *
     * `params`:
     * - `entity`: The ID of the entity whose components will be fetched.
     * - `components`: An array of [fully-qualified type names] of components to fetch.
     * - `signal`: A signal object that allows you to abort it if required via an {@link AbortController} object.
     * - `observer`: A handler of chunks of Response.
     *
     * `result`:
     * - `components`: A map of components added or changed in the last tick associating each type
     *   name to its value on the requested entity.
     * - `removed`: An array of fully-qualified type names of components removed from the entity
     *   in the last tick.
     * - `errors`: A map associating each type name with an error if it was not on the entity
     *   or could not be reflected.
     */
    get_watch(entity: EntityId, components: TypePath[], signal: AbortSignal, observer: (arg: BrpGetWatchResult) => void): Promise<null>;
    /**
     * Watch the values of one or more components from an entity.
     *
     * This function passes a flag `strict` as `true` by default.
     * Response will fail if any one of the components is not present or can not be refleceted.
     *
     * `params`:
     * - `entity`: The ID of the entity whose components will be fetched.
     * - `components`: An array of [fully-qualified type names] of components to fetch.
     * - `signal`: A signal object that allows you to abort it if required via an {@link AbortController} object.
     * - `observer`: A handler of chunks of Response.
     *
     * `result`:
     * - `components`: A map of components added or changed in the last tick associating each type
     *   name to its value on the requested entity.
     * - `removed`: An array of fully-qualified type names of components removed from the entity
     *   in the last tick.
     */
    get_watch_strict(entity: EntityId, components: TypePath[], signal: AbortSignal, observer: (arg: BrpGetWatchStrictResult) => void): Promise<null>;
    /**
     * Watch all components present on an entity.
     *
     * When `entity` is not provided, this lists all registered components. If `entity` is provided,
     * this lists only those components present on the provided entity.
     *
     * `params`:
     * - `signal`: A signal object that allows you to abort it if required via an {@link AbortController} object.
     * - `observer`: A handler of chunks of Response.
     * - `entity`: (optional) The ID of the entity whose components will be listed.
     *
     * `result`:
     * - `added`: An array of fully-qualified type names of components added to the entity in the
     *   last tick.
     * - `removed`: An array of fully-qualified type names of components removed from the entity
     *   in the last tick.
     */
    list_watch(signal: AbortSignal, observer: (arg: BrpListWatchResult) => void, entity?: EntityId): Promise<null>;
}

declare function short(typePath: TypePath): string;

export { BevyRemoteProtocol, type BrpError, type BrpErrors, type BrpGetWatchResult, type BrpGetWatchStrictResult, type BrpListWatchResult, type BrpObject, type BrpResponse, BrpStructure, type BrpStructurePath, type BrpValue, type EntityId, ServerVersion, type TypePath, short };
