import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { URL } from '../mocks/url';

@Injectable({
  providedIn: 'root'
})
export class AuthService {

    constructor(
        private http: HttpClient
    ) { }

    authenticateUser(credentials: { username: string, password: string, login_type: string }) {
        return this.http.post(URL + '/api/auth/signin/', credentials).toPromise();
    }

    requestMailOTP(email: string) {
        return this.http.post(URL + '/api/otp/generate/', { email: email }).toPromise();
    }

    signupUser(credentials: any) {
        return this.http.post(URL + '/api/auth/signup/', credentials).toPromise();
    }

    updateUser(userData: any) {
        const httpOptions = {
			headers: new HttpHeaders({
				'Access-Control-Allow-Origin': '*',
				'Content-Type': 'application/json',
				'Authorization': 'Bearer ' + localStorage.access_Token
			})
        };
        
        return this.http.put(URL + '/api/maioraservice/user/v1/update', userData, httpOptions).toPromise();
    }
}
