import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../../../environments/environment';
import { DataTableData } from '../../model/data-table/data-table-data';
import { DataTableRequest } from '../../model/data-table/data-table-request';
import { DatasetListingModel } from '../../model/dataset/dataset-listing';
import { DatasetProfileModel } from '../../model/dataset/dataset-profile';
import { DatasetCriteria } from '../../query/dataset/dataset-criteria';
import { ExploreDatasetCriteriaModel } from '../../query/explore-dataset/explore-dataset-criteria';
import { BaseHttpService } from '../http/base-http.service';
import { DatasetProfileCriteria } from '../../query/dataset-profile/dataset-profile-criteria';

@Injectable()
export class DatasetService {

	private actionUrl: string;

	constructor(private http: BaseHttpService) {
		this.actionUrl = environment.Server + 'datasets/';
	}

	getPaged(dataTableRequest: DataTableRequest<DatasetCriteria>): Observable<DataTableData<DatasetListingModel>> {
		return this.http.post<DataTableData<DatasetListingModel>>(this.actionUrl + 'paged', dataTableRequest);
	}

	getPublicPaged(dataTableRequest: DataTableRequest<ExploreDatasetCriteriaModel>): Observable<DataTableData<DatasetListingModel>> {
		return this.http.post<DataTableData<DatasetListingModel>>(this.actionUrl + 'public/paged', dataTableRequest);
	}

	makeDatasetPublic(id: String) {
		return this.http.get(this.actionUrl + 'makepublic/' + id);
	}

	getDatasetProfiles(dataTableRequest: DataTableRequest<DatasetProfileCriteria>): Observable<DatasetProfileModel[]> {
		return this.http.post<DatasetProfileModel[]>(environment.Server + 'datasetprofiles/getAll', dataTableRequest);
	}

	getDatasetProfilesUsedPaged(dataTableRequest: DataTableRequest<DatasetProfileCriteria>) {
		return this.http.post<DataTableData<DatasetListingModel>>(this.actionUrl + 'datasetProfilesUsedByDatasets/paged', dataTableRequest);
	}
}
