import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../environments/environment';
import { HappinessWeek } from '../entity/HappinessGroup';

const HappinessWeek_URL = (id: string = null) => { return `${environment.apiUrl}/HappinessWeek${(id ? `/${id}` : '')}` }
@Injectable({
  providedIn: 'root'
})
export class HappinessWeekService {

  constructor(private http: HttpClient,) { }

  get(id: string): Observable<HappinessWeek> {
    return this.http.get<HappinessWeek>(HappinessWeek_URL(id));
  }

  getAll(): Observable<HappinessWeek[]> {
    return this.http.get<HappinessWeek[]>(HappinessWeek_URL());
  }

  create(datum: HappinessWeek) {
    return this.http.post<boolean>(HappinessWeek_URL(), JSON.stringify(datum),
      {
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        }
      }
    );
  }

  update(datum: HappinessWeek) {
    return this.http.put<boolean>(HappinessWeek_URL(datum.weekId), JSON.stringify(datum),
      {
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        }
      }
    );
  }

  delete(datum: HappinessWeek) {
    return this.http.delete<boolean>(HappinessWeek_URL(datum.weekId));
  }
}