import { Injectable } from '@angular/core';
import {HttpClient, HttpRequest, HttpEvent} from '@angular/common/http';
import { Observable } from 'rxjs';
import { User } from '../../core/entities';

@Injectable()
export class ProfilEditionService {
	constructor(private http: HttpClient) {}

	uploadAvatarPicture(file: File): Observable<HttpEvent<{}>> {
		const formData: FormData = new FormData();

		formData.append('file', file);

		return this.http.request(new HttpRequest(
			'POST', '/api/images/uploadAvatar', formData, {
				reportProgress: true,
				responseType: 'text'
			}
		));
	}

	updateUser(user: User): Observable<any> {
		return this.http.put<any>(`/api/account/`, user);
	}
}
