import { Injectable, NgZone } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ProfileModel, UserModel } from '../user-auth.model';
import { UserProfileModel } from 'src/app/models/user.model';
import { environment } from 'src/environments/environment';
@Injectable({
  providedIn: 'root',
})
export class AuthService {
  apiBaseUrl = environment.baseUrl + "/auth";
  constructor(
    private http: HttpClient,
  ) {
  }

  login(username: string, password: string) {
    const body = {
      email: username,
      password: password,
    };
    return this.http.post<UserModel>(this.apiBaseUrl + '/login', body)
  }

  refreshToken(token: string) {
    return this.http.post<any>(this.apiBaseUrl + "/refresh-token", {
      "refreshToken": token
    });
  }

  register(body: UserModel) {
    return this.http.post<any>(this.apiBaseUrl + "/register", new UserProfileModel());
  }

}
