import
{
    SortDirection,
    ResponseContainerDTO,
    IdLocationNameEntityIdentityDTO,
    BaseEntityDTO,
    ItemResponseDTO,
    SortConditionDTO
} from "./Windream.WebService";


export interface ISearchController
{
    Search(parameter: SearchDTO): SearchResponseContainerDTO;
    GetResult(parameter: GetSearchResultDTO): SearchResponseContainerDTO;
    DisposeSearch(parameter: DisposeSearchDTO): ResponseContainerDTO;
}

export const enum SearchAttributeFlagsDTO
{
    Default = 0,
    Objecttype = 2,
    Values = 16,
    System = 32,
    OnlySearchable = 128
}

export const enum SearchMode
{
    Undefined = 0,
    Synchronous = 1,
    Asynchronous = 2
}

export const enum SearchOperator
{
    Undefined = 0,
    Equal = 1,
    NotEqual = 2,
    Lesser = 3,
    Greater = 4,
    LesserEqual = 5,
    GreaterEqual = 6,
    StringLike = 7,
    BitSet = 8,
    BitNotSet = 9,
    In = 10,
    NotIn = 11,
    Exists = 12,
    NotExists = 13,
    StringNotLike = 14,
    InSubTree = 15,
    NotInSubTree = 16,
    SetExactMatch = 17,
    NotSetExactMatch = 18,
    SetMatchesAny = 19,
    NotSetMatchesAny = 20,
    SetMatchesAll = 21,
    NotSetMatchesAll = 22,
    FulltextSpecial = 23,
    Between = 24,
    BetweenEqual = 25
}

export const enum SearchRelation
{
    Undefined = 0,
    And = 1,
    Or = 2,
    GroupBy = 3,
    Having = 4
}

export const enum SearchState
{
    Searching = 0,
    Finished = 1,
    Error = 2,
    Extracting = 3
}

export interface DisposeSearchDTO
{
    ResultId: String;
}

export interface GetSearchResultDTO
{
    Amount: number;
    DisposeResult: boolean;
    Offset: number;
    SearchId: String;
}

export interface SearchConditionDTO
{
    AutoWildcards?: boolean;
    Column?: string;
    LeftBrackets?: number;
    Name?: string;
    RightBrackets?: number;
    SearchOperator: SearchOperator;
    SearchRelation?: SearchRelation;
    Value: any | null;
    SubItems?: IdLocationNameEntityIdentityDTO[];
}

export interface SearchDTO
{
    AttributeFlags?: SearchAttributeFlagsDTO;
    Conditions: SearchConditionDTO[];
    Entity: BaseEntityDTO;
    Mode: SearchMode;
    Sorting?: SortConditionDTO;
    Values?: string[];
}

export interface SearchResponseContainerDTO extends ResponseContainerDTO
{
    Count: number;
    Result: ItemResponseDTO[];
    ResultId: String;
    State: SearchState;
}