import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { NewVisitor } from '../../entity/NewVisitor';
import { CrudService } from './crud.service';
import { first, map } from 'rxjs/operators';
import { DomainMemberRelationship } from '../../entity/PastoralDomain';

const BASE_URL = (action: string = null) => { return `DomainMemberShip${(action ? `/${action}` : '')}` }
const POST_URL_ASSIGN_CELL_GROUPS = 'DomainMemberShip/AssignCellGroups'
const GET_URL_ADD_MEMBER_INTO_GROUP = (domainId, memberId) => `DomainMemberShip/AddMemberIntoGroup?domainId=${domainId}&memberId=${memberId}`;
const GET_URL_REMOVE_MEMBER_FROM_GROUP = (domainId, memberId) => `DomainMemberShip/RemoveMemberFromGroup?domainId=${domainId}&memberId=${memberId}`;
const POST_URL_UPDATE_MEMBERS_IN_GROUP = 'DomainMemberShip/UpdateMembersInGroup'


@Injectable({
  providedIn: 'root'
})
export class DomainMemberShipService extends CrudService<DomainMemberRelationship> {

  constructor(protected http: HttpClient) {
    super(http, BASE_URL);
  }
  assignCellGroups(data) {
    return this.http.post<boolean>(POST_URL_ASSIGN_CELL_GROUPS,
      JSON.stringify(data), {
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
    });

  }
  addMemberIntoGroup(domainId: string, memberId: string) {
    return this.http.get<number>(GET_URL_ADD_MEMBER_INTO_GROUP(domainId, memberId));
  }

  removeMemberFromGroup(domainId: string, memberId: string) {
    return this.http.get<number>(GET_URL_REMOVE_MEMBER_FROM_GROUP(domainId, memberId));
  }

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

  }

}
