import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {AppConfig} from "../../config/app.config";
import {User} from "../model/user";

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

  constructor(private httpClient: HttpClient) { }
  public login(username: string, password: string) {
    const data = {username, password};
    return this.httpClient.post(`${AppConfig.ApiPaths.login}`, data);
  }
  public startChangingPassword(username: string) {
    return this.httpClient.post(`${AppConfig.ApiPaths.startChangingPassword}`, username);
  }
  public checkToken(token: string) {
    return this.httpClient.get<User>(`${AppConfig.ApiPaths.getUserName}`+"/"+token);
  }
  public changePassword(username: string,password:string) {
    const data = {username, password};
    return this.httpClient.post(`${AppConfig.ApiPaths.changePassword}`, data);
  }
}
