import {Injectable} from '@angular/core';
import {ApiService} from "../../shared/service/api.service";
import {Observable} from "rxjs";
import {Company} from "../../shared/model/company.model";

@Injectable({
  providedIn: 'root'
})
export class CompanyService {
  constructor(
    private api: ApiService
  ) {
  }

  get all(): Observable<Company[]> {
    return this.api.get<Company[]>('/company')
  }

  getById(id: number): Observable<Company> {
    return this.api.get<Company>(`/company/${id}`)
  }

  save(name: string): Observable<void> {
    return this.api.post<void>('/company', {name})
  }

  update(id: number, name: string): Observable<void> {
    return this.api.put<void>('/company', {id, name})
  }

  delete(id: number): Observable<void> {
    return this.api.delete<void>(`/company/${id}`)
  }
}
