declare namespace datasources {
  interface ICurrentPage<T extends IEntity = IEntity> {
    first: number;
    size: number;
    entitiesDef: T[];
  }

  type IEntitySelectionSettings = Partial<{
    expand: string;
    relatedSelURI: string;
    queryStr: string;
    queryParams: string;
    first: number;
    pageLength: number;
    filterAttributes: string;
    dataSetName: string;
  }>;

  interface IEntitySelectionPrivate<T extends IEntity = IEntity> {
    curPage: ICurrentPage<T>;
    selLength: number;
    maxEntities: number;
    initialFirst: number;
    pageLength: number;
    inited: boolean;
    owner: DataClass<T>;
    fetching: boolean;
    settings: IEntitySelectionSettings;
    isRelatedSel: boolean;
    relatedSelURI: string;
    dataSetName: string;
    filterAttributes: string;
  }

  interface IDescriptorAsParam {
    __ENTITIES: boolean;
    __DATACLASS: string;
    __DATASET: string;
  }

  class EntitySelection<T extends IEntity = IEntity> {
    constructor(
      owner: DataClass<T>,
      settings: IEntitySelectionSettings,
      rawDef: IDataClass,
    );

    readonly length: number;
    initAsEmpty(): void;
    getLength(settings?: IEntitySelectionSettings): Promise<number>;
    getMaxEntities(): number;
    getDataClass(): DataClass<T>;
    getDescriptorAsParam(): IDescriptorAsParam;
    getComputedURL(
      settings?: IEntitySelectionSettings,
      forFuncCall?: boolean,
    ): {
      url: string;
      added: string;
    };
    fetchPage(
      first: number,
      size: number,
      settings?: IEntitySelectionSettings,
    ): Promise<ICollection<T>>;
    managePage(rawDef: ICollection<T>, nochangeInCurpage?: boolean): T[];
  }
}
