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://b872-2405-9800-bc03-3665-282a-83c6-a83e-fc1b.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");
    }
}