import { HttpHeaders } from '@angular/common/http';
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 { UserListingModel } from '../../model/user/user-listing';
import { UserCriteria } from '../../query/user/user-criteria';
import { BaseHttpService } from '../http/base-http.service';

@Injectable()
export class UserService {

	private actionUrl: string;
	private headers: HttpHeaders;

	constructor(private http: BaseHttpService) {

		this.actionUrl = environment.Server + 'user/';
	}

	getPaged(dataTableRequest: DataTableRequest<UserCriteria>): Observable<DataTableData<UserListingModel>> {
		return this.http.post<DataTableData<UserListingModel>>(this.actionUrl + 'getPaged', JSON.stringify(dataTableRequest), { headers: this.headers });
	}

	getUser(id: String): Observable<UserListingModel> {
		return this.http.get<UserListingModel>(this.actionUrl + id, { headers: this.headers });
	}

	updateRoles(itemToUpdate: UserListingModel): Observable<UserListingModel> {
		return this.http.post<UserListingModel>(this.actionUrl + 'updateRoles', JSON.stringify(itemToUpdate), { headers: this.headers });
	}

	delete(id: String): Observable<any> {
		return this.http.delete<any>(this.actionUrl + id, { headers: this.headers });
	}

	getRecentActivity(): Observable<any[]> {
		return this.http.get<any[]>(this.actionUrl + 'recentActivity', { headers: this.headers });
	}

	updateUserSettings(value: any): Observable<any[]> {
		return this.http.post<any[]>(this.actionUrl + 'settings', value, { headers: this.headers });
	}

	getCollaboratorsPaged(dataTableRequest: DataTableRequest<UserCriteria>): Observable<DataTableData<UserListingModel>> {
		return this.http.post<DataTableData<UserListingModel>>(this.actionUrl + 'getCollaboratorsPaged', JSON.stringify(dataTableRequest), { headers: this.headers });
	}
}
