import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Contact } from "../models/contact.model";

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

    constructor(private http: HttpClient) { }
    url: string = "http://5fa9-110-169-221-194.ngrok.io";
    listContact: Contact[] = []

    addContact(model: Contact) {
        this.listContact.push(model);
        this.listContact.reverse
    }

    updateContact(model: Contact) {
        this.http.put(this.url + "/contact/" +model.id, model).subscribe(response => {
          console.log(response);
          alert("อัพเดทข้อมูลการติดต่อสำเร็จ")
        })
      }

    getListContact(): Observable<Contact[]> {
        return this.http.get<Contact[]>(this.url + "/contact/lists");
    }
}