import * as chevrotain0 from "chevrotain";
import { CstNode, CstParser, ICstVisitor, IToken, Lexer } from "chevrotain";

//#region src/lexer.d.ts
declare const searchSyntaxLexer: Lexer;
//#endregion
//#region src/parser.d.ts
declare class SearchSyntaxParser extends CstParser {
  [key: string]: any;
  constructor();
}
declare const searchSyntaxParser: SearchSyntaxParser;
//#endregion
//#region src/interfaces/FieldOptions.d.ts
interface BaseFieldOptions {
  array?: boolean;
  searchable?: boolean;
}
interface StringFieldOptions extends BaseFieldOptions {
  type: "string";
  fulltext?: boolean;
  prefix?: boolean;
}
interface NonStringFieldOptions extends BaseFieldOptions {
  type: "number" | "boolean" | "date";
}
type FieldOptions = StringFieldOptions | NonStringFieldOptions;
//#endregion
//#region src/interfaces/ParseOptions.d.ts
interface ParseOptions {
  fields?: Record<string, FieldOptions>;
  aliases?: Record<string, string>;
  timezone?: string;
}
//#endregion
//#region src/interfaces/index.d.ts
type ArrayElement<T> = T extends ReadonlyArray<infer U> ? T | U : T;
interface ComparisonOperators<T = unknown> {
  $eq?: T;
  $gt?: T;
  $gte?: T;
  $lt?: T;
  $lte?: T;
  $in?: T[];
  $contains?: T[];
  $fulltext?: string;
  $prefix?: string;
}
interface LogicalOperators<T = Record<string, unknown>> {
  $and?: Array<Filter<T>>;
  $or?: Array<Filter<T>>;
  $not?: Filter<T>;
  $nor?: Array<Filter<T>>;
}
type Filter<T = Record<string, unknown>> = { [P in keyof T]?: ArrayElement<T[P]> | ComparisonOperators<ArrayElement<T[P]>> } & LogicalOperators<T>;
type ComparatorOperators<T = unknown> = ComparisonOperators<T>;
type ConnectiveOperators<T = Record<string, unknown>> = LogicalOperators<T>;
type AlternativeType<T> = ArrayElement<T>;
//#endregion
//#region src/enums/Comparator.d.ts
declare enum Comparator {
  EQ = "EQ",
  LT = "LT",
  GT = "GT",
  LE = "LE",
  GE = "GE",
}
//#endregion
//#region src/enums/Connective.d.ts
declare enum Connective {
  AND = "AND",
  OR = "OR",
}
//#endregion
//#region src/enums/NodeType.d.ts
declare enum NodeType {
  QUERY = "query",
  TERM = "term",
}
//#endregion
//#region src/cst.d.ts
interface QueryCstNode extends CstNode {
  name: "query";
  children: QueryCstChildren;
}
type QueryCstChildren = {
  orQuery: OrQueryCstNode[];
};
interface OrQueryCstNode extends CstNode {
  name: "orQuery";
  children: OrQueryCstChildren;
}
type OrQueryCstChildren = {
  andQuery: (AndQueryCstNode)[];
  Or?: IToken[];
};
interface AndQueryCstNode extends CstNode {
  name: "andQuery";
  children: AndQueryCstChildren;
}
type AndQueryCstChildren = {
  atomicQuery: (AtomicQueryCstNode)[];
  And?: IToken[];
};
interface AtomicQueryCstNode extends CstNode {
  name: "atomicQuery";
  children: AtomicQueryCstChildren;
}
type AtomicQueryCstChildren = {
  subQuery?: SubQueryCstNode[];
  notQuery?: NotQueryCstNode[];
  term?: TermCstNode[];
};
interface SubQueryCstNode extends CstNode {
  name: "subQuery";
  children: SubQueryCstChildren;
}
type SubQueryCstChildren = {
  LeftBracket: IToken[];
  query: QueryCstNode[];
  RightBracket: IToken[];
};
interface NotQueryCstNode extends CstNode {
  name: "notQuery";
  children: NotQueryCstChildren;
}
type NotQueryCstChildren = {
  Not: IToken[];
  atomicQuery: AtomicQueryCstNode[];
};
interface TermCstNode extends CstNode {
  name: "term";
  children: TermCstChildren;
}
type TermCstChildren = {
  equalFieldTerm?: EqualFieldTermCstNode[];
  otherFieldTerm?: OtherFieldTermCstNode[];
  globalTerm?: GlobalTermCstNode[];
};
interface EqualFieldTermCstNode extends CstNode {
  name: "equalFieldTerm";
  children: EqualFieldTermCstChildren;
}
type EqualFieldTermCstChildren = {
  field: FieldCstNode[];
  Equal: IToken[];
  value: ValueCstNode[];
  Comma?: IToken[];
};
interface OtherFieldTermCstNode extends CstNode {
  name: "otherFieldTerm";
  children: OtherFieldTermCstChildren;
}
type OtherFieldTermCstChildren = {
  field: FieldCstNode[];
  LessThan?: IToken[];
  LessThanOrEqual?: IToken[];
  GreaterThan?: IToken[];
  GreaterThanOrEqual?: IToken[];
  value: ValueCstNode[];
};
interface GlobalTermCstNode extends CstNode {
  name: "globalTerm";
  children: GlobalTermCstChildren;
}
type GlobalTermCstChildren = {
  value: ValueCstNode[];
};
interface FieldCstNode extends CstNode {
  name: "field";
  children: FieldCstChildren;
}
type FieldCstChildren = {
  Field: IToken[];
};
interface ValueCstNode extends CstNode {
  name: "value";
  children: ValueCstChildren;
}
type ValueCstChildren = {
  Value: IToken[];
};
interface ICstNodeVisitor<IN, OUT> extends ICstVisitor<IN, OUT> {
  query(children: QueryCstChildren, param?: IN): OUT;
  orQuery(children: OrQueryCstChildren, param?: IN): OUT;
  andQuery(children: AndQueryCstChildren, param?: IN): OUT;
  atomicQuery(children: AtomicQueryCstChildren, param?: IN): OUT;
  subQuery(children: SubQueryCstChildren, param?: IN): OUT;
  notQuery(children: NotQueryCstChildren, param?: IN): OUT;
  term(children: TermCstChildren, param?: IN): OUT;
  equalFieldTerm(children: EqualFieldTermCstChildren, param?: IN): OUT;
  otherFieldTerm(children: OtherFieldTermCstChildren, param?: IN): OUT;
  globalTerm(children: GlobalTermCstChildren, param?: IN): OUT;
  field(children: FieldCstChildren, param?: IN): OUT;
  value(children: ValueCstChildren, param?: IN): OUT;
}
//#endregion
//#region src/cst-visitor.d.ts
declare const BaseCstVisitor: new (...args: any[]) => chevrotain0.ICstVisitor<any, any>;
declare class SearchSyntaxCstVisitor<T> extends BaseCstVisitor implements ICstNodeVisitor<any, any> {
  private readonly options?;
  constructor(options?: ParseOptions | undefined);
  query(ctx: QueryCstChildren): Filter<T>;
  orQuery(ctx: OrQueryCstChildren): LogicalOperators<T>;
  andQuery(ctx: AndQueryCstChildren): LogicalOperators<T> | Filter<T>;
  private mergeAndConditions;
  private canMerge;
  atomicQuery(ctx: AtomicQueryCstChildren): Filter<T>;
  subQuery(ctx: SubQueryCstChildren): Filter<T>;
  notQuery(ctx: NotQueryCstChildren): Filter<T>;
  term(ctx: TermCstChildren): ComparisonOperators<T> | LogicalOperators<T> | undefined;
  globalTerm(ctx: GlobalTermCstChildren): LogicalOperators<T>;
  equalFieldTerm(children: EqualFieldTermCstChildren): ComparisonOperators<T> | undefined;
  otherFieldTerm(children: OtherFieldTermCstChildren): ComparisonOperators<T> | undefined;
  field(ctx: FieldCstChildren): string;
  value(children: ValueCstChildren, type?: FieldOptions["type"]): any;
}
//#endregion
//#region src/parse.d.ts
declare function parse<T = Record<string, any>>(query?: string, options?: ParseOptions): Filter<T> | null;
//#endregion
//#region src/tokens.d.ts
declare const ComparatorToken: chevrotain0.TokenType;
declare const FieldToken: chevrotain0.TokenType;
declare const ValueToken: chevrotain0.TokenType;
declare const GreaterThanOrEqualToken: chevrotain0.TokenType;
declare const GreaterThanToken: chevrotain0.TokenType;
declare const LessThanOrEqualToken: chevrotain0.TokenType;
declare const LessThanToken: chevrotain0.TokenType;
declare const EqualToken: chevrotain0.TokenType;
declare const LeftBracketToken: chevrotain0.TokenType;
declare const RightBracketToken: chevrotain0.TokenType;
declare const CommaToken: chevrotain0.TokenType;
declare const UnquotedLiteralToken: chevrotain0.TokenType;
declare const IdentifierToken: chevrotain0.TokenType;
declare const QuotedStringToken: chevrotain0.TokenType;
declare const DateToken: chevrotain0.TokenType;
declare const NumberToken: chevrotain0.TokenType;
declare const NullToken: chevrotain0.TokenType;
declare const TrueToken: chevrotain0.TokenType;
declare const FalseToken: chevrotain0.TokenType;
declare const NestedFieldToken: chevrotain0.TokenType;
declare const AndToken: chevrotain0.TokenType;
declare const OrToken: chevrotain0.TokenType;
declare const NotToken: chevrotain0.TokenType;
declare const WhiteSpaceToken: chevrotain0.TokenType;
declare const tokens: chevrotain0.TokenType[];
//#endregion
//#region src/errors/ParseError.d.ts
declare class ParseError extends Error {
  readonly query: string;
  constructor(message: string, query: string);
}
//#endregion
//#region src/errors/NoSearchableFieldsError.d.ts
declare class NoSearchableFieldsError extends Error {
  readonly term: string;
  constructor(term: string);
}
//#endregion
//#region src/utils/hasValidValues.d.ts
declare function hasValidValues(obj: unknown): boolean;
//#endregion
export { AlternativeType, AndQueryCstChildren, AndQueryCstNode, AndToken, ArrayElement, AtomicQueryCstChildren, AtomicQueryCstNode, CommaToken, Comparator, ComparatorOperators, ComparatorToken, ComparisonOperators, Connective, ConnectiveOperators, DateToken, EqualFieldTermCstChildren, EqualFieldTermCstNode, EqualToken, FalseToken, FieldCstChildren, FieldCstNode, FieldOptions, FieldToken, Filter, GlobalTermCstChildren, GlobalTermCstNode, GreaterThanOrEqualToken, GreaterThanToken, ICstNodeVisitor, IdentifierToken, LeftBracketToken, LessThanOrEqualToken, LessThanToken, LogicalOperators, NestedFieldToken, NoSearchableFieldsError, NodeType, NotQueryCstChildren, NotQueryCstNode, NotToken, NullToken, NumberToken, OrQueryCstChildren, OrQueryCstNode, OrToken, OtherFieldTermCstChildren, OtherFieldTermCstNode, ParseError, ParseOptions, QueryCstChildren, QueryCstNode, QuotedStringToken, RightBracketToken, SearchSyntaxCstVisitor, SearchSyntaxParser, SubQueryCstChildren, SubQueryCstNode, TermCstChildren, TermCstNode, TrueToken, UnquotedLiteralToken, ValueCstChildren, ValueCstNode, ValueToken, WhiteSpaceToken, hasValidValues, parse, searchSyntaxLexer, searchSyntaxParser, tokens };