/**
 * @author Roman Vottner
 * @copyright 2020 Roman Vottner
 * @license Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import type { Tokenizer } from './tokenizer';
export declare class Dictionary<T> {
    private entries;
    constructor(data?: {
        [key: string]: T;
    });
    contains(key: string): boolean;
    get(key: string): T | undefined;
    keys(): string[];
    add(key: string, value: T): T;
    length(): number;
}
export type Component = {
    id: string;
    name: string;
    value?: string | ComponentValue;
    format: string;
};
export type SegmentEntry = {
    requires: number;
    elements: ElementEntry[];
};
export type ElementEntry = {
    id: string;
    name: string;
    requires: number;
    components: Component[];
};
export type ComponentValue = {
    id: string;
    value: string;
    description: string;
    deprecated?: boolean;
};
export type ComponentValueEntry = {
    [key: string]: ComponentValue;
};
interface FormatType {
    alpha: boolean;
    numeric: boolean;
    minimum: number;
    maximum: number;
}
export declare enum ValidatorStates {
    /**
     * Setting validation to none will disable the validator completely. The
     * validator will not even try to obtain a segment description for segments
     * encountered. Almost all overhead is eliminated in this state.
     */
    NONE = 0,
    /**
     * The segments state implies no segment definition was found for the current
     * segment, so validation should be disabled for its elements and components.
     * Normal validation should be resumed, however, as of the next segment.
     */
    SEGMENTS = 1,
    /**
     * The elements state is equivalent to the segments state, but validation is
     * only temporary disabled for the current element. Normal validation resumes
     * as of the next element.
     */
    ELEMENTS = 2,
    /**
     * Validation is enabled for all entities, including segments, elements and
     * components.
     */
    ALL = 3,
    ENTER = 4,
    ENABLE = 5
}
export interface Validator {
    onOpenSegment(segment: string): SegmentEntry | undefined;
    onElement(): ElementEntry | undefined;
    onOpenComponent(buffer: Tokenizer): void;
    onCloseComponent(buffer: Tokenizer): Component | undefined;
    onCloseSegment(segment: string): void;
    disable(): void;
    enable(): void;
    define(definitions: Dictionary<SegmentEntry>): void;
    format(formatString: string): FormatType | undefined;
}
export declare class NullValidator implements Validator {
    onOpenSegment(): undefined;
    onElement(): undefined;
    onOpenComponent(): void;
    onCloseComponent(): undefined;
    onCloseSegment(): void;
    disable(): void;
    enable(): void;
    define(): void;
    format(): FormatType | undefined;
}
/**
 * The `Validator` can be used as an add-on to `Parser` class, to enable
 * validation of segments, elements and components. This class implements a
 * tolerant validator, only segments and elemens for which definitions are
 * provided will be validated. Other segments or elements will pass through
 * untouched. Validation includes:
 * * Checking data element counts, including mandatory elements.
 * * Checking component counts, including mandatory components.
 * * Checking components against they're required format.
 */
export declare class ValidatorImpl implements Validator {
    private segments;
    private formats;
    private counts;
    private state;
    private segment;
    private element;
    private component;
    private required;
    private minimum;
    private maximum;
    private throwOnMissingDefinitions;
    constructor(throwOnMissingDefinitions?: boolean);
    /**
     * @summary Enable validation on the next segment.
     */
    disable(): void;
    /**
     * @summary Enable validation on the next segment.
     */
    enable(): void;
    define(definitions: Dictionary<SegmentEntry>): void;
    /**
     * @summary Request a component definition associated with a format string.
     * @returns A component definition.
     */
    format(formatString: string): FormatType | undefined;
    /**
     * Called when a adding a new segment to the parser
     * @param segment The segment as a string
     * @returns The segment entry
     */
    onOpenSegment(segment: string): SegmentEntry | undefined;
    onElement(): ElementEntry | undefined;
    /**
     * @summary Start validation for a new component.
     * @param buffer - An object which implements the buffer interface.
     *
     * The buffer object should allow the mode to be set to alpha, numeric or
     * alphanumeric with their corresponding methods.
     */
    onOpenComponent(buffer: Tokenizer): void;
    onCloseComponent(buffer: Tokenizer): Component | undefined;
    /**
     * @summary Finish validation for the current segment.
     */
    onCloseSegment(segment: string): void;
    private errors;
}
export {};
//# sourceMappingURL=validator.d.ts.map