import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from '../../../environments/environment';
import { CellGroupRoutineEventAttendee, CellGroupRoutineEvents } from '../../entity/CellGroupRoutineEvents';

const CellGroupRoutineEvents_URL = (id: string = null) => { return `${environment.apiUrl}/CellGroupRoutineEvents${(id ? `/${id}` : '')}` }
const POST_URL_CREATE_OR_UPDATE_PRAYER = 'CellGroupRoutineEvents/CreateOrUpdatePrayer'
@Injectable({
  providedIn: 'root'
})
export class CellGroupRoutineEventsService {

  constructor(private http: HttpClient) { }

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

  getComingEvent(): Observable<CellGroupRoutineEvents> {
    return this.http.get<CellGroupRoutineEvents>(CellGroupRoutineEvents_URL('GetComingEvent'));
  }
  getLastEvent(): Observable<CellGroupRoutineEvents> {
    return this.http.get<CellGroupRoutineEvents>(CellGroupRoutineEvents_URL('GetLastEvent'));
  }

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

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

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

  delete(datum: CellGroupRoutineEvents) {
    return this.http.delete<boolean>(CellGroupRoutineEvents_URL(datum.id));
  }

  createOrUpdateAttendee(datum: CellGroupRoutineEventAttendee) {

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

  createOrUpdatePrayer(data) {
    return this.http.post<boolean>(POST_URL_CREATE_OR_UPDATE_PRAYER,
      JSON.stringify(data), {
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
    });

  }

}