// import { DataModel } from '../../../core/src/models/data-model';
// import { Comparison, Filter } from '../../../core/src/models/filter';
// import { ListFetchState } from '../../../core/src/models/list-fetch-state';
// import { QuickSearchConfig } from '../../../core/models/quick-search-config';
// import { ListQueryConfig } from '../../../core/views/dvn-list-view-container/dvn-list-view-container';
// import { createDataApiInstance, DvnDataApi } from '../../../dvn-data-api-js-client';
// import { ComponentDataProvider } from './ComponentDataProvider';
//
// function buildQuery(query: ListQueryConfig, quickFilter: Filter): Filter {
//   let queryFilter: Filter = query ? query.filter : undefined;
//   if (quickFilter) {
//     if (query && query.filter) {
//       queryFilter = {
//         operator: 'and',
//         filters: [query.filter, quickFilter]
//       };
//     } else {
//       queryFilter = quickFilter;
//     }
//   }
//   return queryFilter;
// }
//
// function generateQuickSearchFilters(quickSearch?: QuickSearchConfig, filter?: string): Filter | undefined {
//   if (!quickSearch || !filter) {
//     return undefined;
//   }
//
//   return {
//     operator: 'or',
//     filters: quickSearch.fields.map(field => ({
//       comparison: Comparison.Contain,
//       id: field.id,
//       value: filter,
//     }))
//   };
// }
//
// export class DvnDataProvider implements ComponentDataProvider<Array<DataModel>> {
//
//   private base: string;
//   private collection: string;
//   private query: ListQueryConfig;
//   private readonly quickSearch?: QuickSearchConfig;
//
//   private quickSearchText?: string;
//
//   private didQuickSearchChangeAfterLastFetch: boolean = false;
//
//   private api: DvnDataApi;
//   private list: ListFetchState = ListFetchState.init();
//   private initialData?: Array<DataModel>;
//
//   constructor(dataApiUrl: string, base: string, collection: string, query: ListQueryConfig, initialData?: Array<DataModel>, quickSearch?: QuickSearchConfig) {
//     this.base = base;
//     this.collection = collection;
//     this.query = query;
//     this.initialData = initialData;
//     this.quickSearch = quickSearch;
//
//     this.api = createDataApiInstance(dataApiUrl);
//   }
//
//   public getInitialData(): Array<DataModel> {
//     return this.initialData;
//   }
//
//   public getData() {
//     const { api, base, collection, query, quickSearchText } = this;
//     const self = this;
//
//     return new Promise<Array<DataModel>>(((resolve, reject) => {
//       if (self.list.data && !this.didQuickSearchChangeAfterLastFetch) {
//         // return already fetched data
//         resolve(self.list.data);
//         return;
//       }
//
//       const queryFilter = buildQuery(query, generateQuickSearchFilters(this.quickSearch, quickSearchText));
//
//       api.query(base, collection, {
//         fields: query.fields,
//         filter: queryFilter,
//         limit: 50,
//         skip: 0,
//         sort: query.sort,
//       }).then(response => {
//         self.list = ListFetchState.init().afterFetch(response);
//         this.didQuickSearchChangeAfterLastFetch = false;
//         resolve(self.list.data);
//       }, error => {
//         self.list = ListFetchState.init().afterFetchError(error);
//         reject(error);
//       });
//     }));
//   }
//
//   public setInitialData(initialData?: Array<DataModel>) {
//     this.initialData = initialData;
//   }
//
//   public setQuickSearchText(text: string) {
//     this.quickSearchText = text;
//     this.didQuickSearchChangeAfterLastFetch = true;
//   }
//
//   public isQuickSearchEnabled(): boolean {
//     return !!this.quickSearch;
//   }
// }
