import { Injectable } from "@angular/core";
import { HttpHeaders } from "@angular/common/http";
import { BaseHttpService } from "../http/base-http.service";
import { environment } from "../../../../environments/environment";
import { Observable } from "rxjs/internal/Observable";
import { DataTableData } from "../../model/data-table/data-table-data";
import { OrganizationModel } from "../../model/organisation/organization";
import { OrganisationCriteria } from "../../query/organisation/organisation-criteria";
import { DataTableRequest } from "../../model/data-table/data-table-request";

@Injectable()
export class OrganisationService {

	private actionUrl: string;
	private headers: HttpHeaders;

	constructor(private http: BaseHttpService) {

		this.actionUrl = environment.Server;

		this.headers = new HttpHeaders();
		this.headers = this.headers.set('Content-Type', 'application/json');
		this.headers = this.headers.set('Accept', 'application/json');
	}

	public searchInternalOrganisations(dataTableRequest: DataTableRequest<OrganisationCriteria>): Observable<DataTableData<OrganizationModel>> {
		return this.http.post<DataTableData<OrganizationModel>>(this.actionUrl + 'internal/organisations', dataTableRequest , { headers: this.headers });
	}

	public searchPublicOrganisations(dataTableRequest: DataTableRequest<OrganisationCriteria>): Observable<DataTableData<OrganizationModel>> {
		return this.http.post<DataTableData<OrganizationModel>>(this.actionUrl + 'public/organisations', dataTableRequest , { headers: this.headers });
	}
}
