import { Injectable } from '@angular/core';
import { User } from '../models/user.model';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { NgForm } from '@angular/forms';

@Injectable({
  providedIn: 'root',
})
export class UserService {
  API_URL = 'http://127.0.0.1:3000';

  private Users: User[] = [];

  constructor(private http: HttpClient) {}

  getUsers(): Observable<any> {
    return this.http.get(`${this.API_URL}/Users`);
  }

  postUser(form: NgForm): void {
    let body = {
      login: form.value.login,
      password: form.value.password,
      permissions: 0,
    };
    this.http.post<any>(`${this.API_URL}/users`, body).subscribe();
  }
}
