import * as i0 from '@angular/core';
import * as i1 from '@angular/common';
import { IdType } from 'imng-nrsrx-client-utils';
import { Observable } from 'rxjs';

declare class ImngODataClientModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<ImngODataClientModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<ImngODataClientModule, never, [typeof i1.CommonModule], never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<ImngODataClientModule>;
}

interface IFilterOperator {
    name: string;
    toODataString: ((field: string, value?: IdType) => string) | ((field: string, value?: IdType[]) => string);
}

/**
 * A basic filter expression.
 */
interface Filter {
    /**
     * The data item field to which the filter operator is applied.
     */
    field: string;
    /**
     * The filter operator (comparison).
     *
     * The supported operators are:
     * * `FilterOperators.equalTo` (equal to)
     * * `FilterOperators.notEqualTo` (not equal to)
     * * `FilterOperators.isNull` (is equal to null)
     * * `FilterOperators.notNull` (is not equal to null)
     * * `FilterOperators.lessThan` (less than)
     * * `FilterOperators.lessThanOrEqualTo` (less than or equal to)
     * * `FilterOperators.greaterThan` (greater than)
     * * `FilterOperators.greaterThanOrEqualTo` (greater than or equal to)
     * * `FilterOperators.in` (specified value should be an array)
     * * `FilterOperators.notIn` (specified value should be an array)
     *
     * The following operators are supported for string fields only:
     * * `FilterOperators.startsWith`
     * * `FilterOperators.endsWith`
     * * `FilterOperators.contains`
     * * `FilterOperators.notContains`
     * * `FilterOperators.isEmpty`
     * * `FilterOperators.notempty`
     */
    operator: IFilterOperator;
    /**
     * The value to which the field is compared. Has to be of the same type as the field.
     */
    value?: IdType | IdType[] | boolean | null;
    /**
     * Determines if the string comparison is case-insensitive.
     */
    ignoreCase?: boolean;
}

/**
 * A complex filter expression.
 */
interface CompositeFilter {
    /**
     * The logical operation to use when the `filter.filters` option is set.
     *
     * The supported values are:
     * * `"and"`
     * * `"or"`
     */
    logic: 'or' | 'and';
    /**
     * The nested filter expressions
     */
    filters: Array<Filter | ChildFilter | CompositeFilter>;
}
declare function isCompositeFilter(source: CompositeFilter | Filter | ChildFilter): source is CompositeFilter;

interface ChildFilter extends Filter {
    /**
     * Used to support child entity filtering:
     * Child table name/navigation property
     * */
    childTable: string;
    /**
     * Used to support child entity filtering:
     * Specifies whether all or some of the child records have to match the given criteria
     * */
    linqOperation: 'all' | 'any';
}
declare function isChildFilter(source: CompositeFilter | Filter | ChildFilter): source is ChildFilter;

declare enum ComputationOperators {
    Multiply = "mul",
    Divide = "div",
    Add = "add",
    Subtract = "sub",
    Modulus = "mod"
}

interface Computation {
    /** This is the first value to be used in the computation */
    fieldA: string | number;
    /** This is the second value to be used in the computation */
    fieldB: string | number;
    operator: ComputationOperators | string;
    /** This MUST differ from the names of declared or dynamic properties of the identified resources. */
    alias: string;
}
declare function isComputation(source: string | Computation): source is Computation;

/**
 * The sort descriptor used by the `orderBy` method.
 */
interface Sort {
    /**
     * The field that is sorted.
     */
    field: string;
    /**
     * The sort direction. If no direction is set, the descriptor will be skipped during processing.
     *
     * The available values are:
     * - `asc` => ascending
     * - `desc` => descending
     */
    dir?: 'asc' | 'desc';
}

interface ODataQuery {
    /**
     * The number of records to be skipped by the pager.
     */
    skip?: number;
    /**
     * The number of records to take.
     */
    top?: number;
    /**
     * The descriptors used for sorting.
     */
    orderBy?: Array<Sort>;
    /**
     * The descriptors used for filtering.
     */
    filter?: CompositeFilter;
    /**
     * Used to specify the retrieval of related tables/entities.
     */
    expand?: Array<Expander>;
    /**
     * Specifies the list of properties to retrieve
     */
    select?: string[];
    /**
     * Request a total count of records.
     * Note: Filter expressions will affect this value.
     * Default: true
     */
    count?: boolean;
    /**
     * Specifies aggregation behavior for the collection of entries.
     */
    apply?: string;
    /**
     * Specifies computed properties that can be used in $select, $filter or $orderby expressions.
     */
    compute?: Array<Computation | string>;
}

interface Expander extends ODataQuery {
    table: string;
}
declare function isExpander(source: string | Expander): source is Expander;

interface FetchOptions {
    /**
     * Collection of child table properties that are rendered on the table
     */
    boundChildTableProperties?: BoundChildTableProperty[];
    /**
     * Collection of property names that are of type: nullable Date
     */
    dateNullableProps?: string[];
    /**
     * Collection of property names that are of type: nullable UTC DateTime
     *    Note: these properties will be converted to local date time
     */
    utcNullableProps?: string[];
    /**
     * Set to true to force request via cache-busting.
     * Default: false;
     */
    bustCache?: boolean;
}
interface BoundChildTableProperty {
    /**
     * This is the child table name
     */
    table: string;
    /**
     * This is the field name on the child table that is bound
     */
    field: string;
    /**
     * This controls if 'all' child records have to meet the the conditions
     * or if 'any' of the child records have to meet the condition.
     * Default: 'any'
     */
    linqOperation?: 'all' | 'any';
}

interface IFilterOperators {
    [key: string]: IFilterOperator;
}
/**
 * Represents the list of supported simple filter operators.
 */
declare class FilterOperators {
    /**
     * The `eq` operator.
     */
    static readonly equals: IFilterOperator;
    /**
     * The `gt` operator.
     */
    static readonly greaterThan: IFilterOperator;
    /**
     * The `ge` operator.
     */
    static readonly greaterThanOrEquals: IFilterOperator;
    /**
     * The `lt` operator.
     */
    static readonly lessThan: IFilterOperator;
    /**
     * The `le` operator.
     */
    static readonly lessThanOrEquals: IFilterOperator;
    /**
     * The `ne` operator.
     */
    static readonly notEquals: IFilterOperator;
    /**
     * The `in` operator.
     */
    static readonly in: IFilterOperator;
    /**
     * The `not in` operator.
     */
    static readonly notIn: IFilterOperator;
    /**
     * The `is not null` operator.
     */
    static readonly notNull: IFilterOperator;
    /**
     * The `is null` operator.
     */
    static readonly isNull: IFilterOperator;
    /**
     * The `contains` operator.
     */
    static readonly contains: IFilterOperator;
    /**
     * The `not contain` operator.
     */
    static readonly notContains: IFilterOperator;
    /**
     * The `ends with` operator.
     */
    static readonly endsWith: IFilterOperator;
    /**
     * The `not ends with` operator.
     */
    static readonly notEndsWith: IFilterOperator;
    /**
     * The `startswith` operator.
     */
    static readonly startsWith: IFilterOperator;
    /**
     * The `not start with` operator.
     */
    static readonly notStartsWith: IFilterOperator;
    /**
     * The `empty` operator.
     */
    static readonly isEmpty: IFilterOperator;
    /**
     * The `not empty` operator.
     */
    static readonly notEmpty: IFilterOperator;
}
declare const filterOperators: IFilterOperators;

interface ODataResult<T extends {
    id?: IdType;
} | unknown> {
    value: T[];
    count?: number;
    '@odata.count'?: number;
}
declare function createEmptyODataResult<T extends {
    id?: IdType;
} | unknown>(): ODataResult<T>;
declare function isODataResult<T extends {
    id?: IdType;
} | unknown>(source: unknown): source is ODataResult<T>;

declare class ODataClientService {
    private readonly httpClient;
    fetch<T extends object>(odataEndpoint: string, query: ODataQuery, options?: FetchOptions): Observable<ODataResult<T>>;
    getODataString(query: ODataQuery, options?: FetchOptions): string;
    processExpanders(query: ODataQuery, queryString: string): string;
    getExpansionString(element: Expander): string;
    processOrderBy(query: ODataQuery, queryString: string): string;
    processFilters(query: ODataQuery, _options: FetchOptions, queryString: string): string;
    serializeCompositeFilter(filter: CompositeFilter): string;
    serializeFilter(filter: Filter | ChildFilter): string;
    processSimpleParameters(parameterName: 'skip' | 'top', query: ODataQuery, queryString: string): string;
    processCacheBusting(options: FetchOptions, queryString: string): string;
    processCount(query: ODataQuery, queryString: string): string;
    processDates(queryString: string): string;
    processGuids(queryString: string): string;
    processSelectors(state: ODataQuery, queryString: string): string;
    static ɵfac: i0.ɵɵFactoryDeclaration<ODataClientService, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<ODataClientService>;
}

declare const getFilterOperator: (operatorName: string) => IFilterOperator;

declare function createODataResult<T extends {
    id?: IdType;
} | unknown>(t: T[]): ODataResult<T>;

declare function serializeValue(value?: IdType): string;
declare const serializeSimpleFilter: (field: string, operator: string, value?: IdType) => string;
declare const serializeArrayFilter: (field: string, operator: string, values?: IdType[]) => string;
declare const serializeFunctionFilter: (field: string, func: string, value?: IdType) => string;

export { ComputationOperators, FilterOperators, ImngODataClientModule, ODataClientService, createEmptyODataResult, createODataResult, filterOperators, getFilterOperator, isChildFilter, isCompositeFilter, isComputation, isExpander, isODataResult, serializeArrayFilter, serializeFunctionFilter, serializeSimpleFilter, serializeValue };
export type { BoundChildTableProperty, ChildFilter, CompositeFilter, Computation, Expander, FetchOptions, Filter, IFilterOperator, IFilterOperators, ODataQuery, ODataResult, Sort };
