
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Staff,StaffSearch, StaffView, ResultModel,ConfigureUrl,ResetPassword }  from '../models';
import { AppSettingService } from '../shares';

@Injectable({ providedIn: 'root' })
export class StaffService {
	public searchCriteria: StaffSearch;
	constructor(private http: HttpClient,
		private appSetting :AppSettingService
		) {
			this.searchCriteria = {
				email:'',
				firstName: '',
				lastName:''
			};
		
		}
	searchStaffs(criteria: StaffSearch): Observable<ResultModel<StaffView[]>> {
		let config = { headers : { 'Content-Type': 'application/json' } };
		const baseUrl = this.appSetting.appSetting.baseUrl + "/"+ ConfigureUrl.staffUrl + "/SearchStaff";
		return this.http.post<ResultModel<StaffView[]>>(baseUrl, criteria, config);
	}
	
	loadStaffById(id:number): Observable<ResultModel<Staff>> {
		const baseUrl = this.appSetting.appSetting.baseUrl + "/"+ ConfigureUrl.staffUrl;
		/*
		const params = new HttpParams().set("id", ""+id);
		const headers = new HttpHeaders().set('Content-Type', 'application/json');
		const options = {
			headers: headers,
			params: params
			}; 
			*/
		//return this.http.get<AdminUser>(this.baseUrl + 'api/Adminuser/LoadAdminuserById',options);
		return this.http.get<ResultModel<Staff>>(baseUrl + "/" + id);
	}
	saveStaff(data:Staff): Observable<ResultModel<number>> { //insert Adminuser
		let config = { headers : { 'Content-Type': 'application/json' } };
		const baseUrl = this.appSetting.appSetting.baseUrl  + "/"+ ConfigureUrl.staffUrl+"/SaveStaff";
		return this.http.post<ResultModel<number>>(baseUrl, data, config);
	}
	saveResetPassword(data:ResetPassword): Observable<ResultModel<number>> { //insert Adminuser
		let config = { headers : { 'Content-Type': 'application/json' } };
		const baseUrl = this.appSetting.appSetting.baseUrl  + "/"+ ConfigureUrl.staffUrl+"/ResetPassStaff";
		return this.http.post<ResultModel<number>>(baseUrl, data, config);
	}
	deleteStaff(id:number): Observable<ResultModel<number>>{
		const baseUrl = this.appSetting.appSetting.baseUrl  + "/"+ ConfigureUrl.staffUrl;
		
		return this.http.delete<ResultModel<number>>(baseUrl + "/" + id);
	}
}
