import {Injectable} from '@angular/core';
import {ResourceBase} from '../../../../core/api/resource';
import {HttpClient, HttpParams} from '@angular/common/http';
import {Observable} from 'rxjs';
import {catchError} from 'rxjs/operators';

@Injectable({
	providedIn: 'root'
})
export class UsuariosService extends ResourceBase {

	constructor(public http: HttpClient) {
		super(http, 'administrador/usuarios');
	}

	public getRoles(url, searchText): Observable<any>{
		let params = new HttpParams()
			.set('perPage', '10')
			.set('visible', '1')
			.set('deleted_at', '1')
			.set('query', (searchText) ? searchText : '');

		let options = {params: params};
		return this.http.get(this.baseUrl + url, options).pipe(
			catchError(this.handleError('index'))
		);
	}

	public filtrosUsuarios(url: string){
		return this.http.get(this.baseUrl + 'administrador/usuarios/' + url).pipe(catchError(this.handleError('index')));
	}

	public getRolesUsuarios(url: string){
		return this.http.get(this.baseUrl + 'administrador/usuarios/' + url).pipe(catchError(this.handleError('index')));
	}
}
