import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '@src/environments/environment';
import { first } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root',
})
export class LocationService {
  constructor(private httpClient: HttpClient) {}

  getAreaNames(): Observable<any> {
    return this.httpClient.get(`${environment.cicMetaUrl}/areanames`);
  }

  getAreaNameByLocation(location: string): Observable<any> {
    return this.httpClient.get(`${environment.cicMetaUrl}/areanames/${location.toLowerCase()}`);
  }

  getAreaTypes(): Observable<any> {
    return this.httpClient.get(`${environment.cicMetaUrl}/areatypes`).pipe(first());
  }

  getAreaTypeByArea(area: string): Observable<any> {
    return this.httpClient
      .get(`${environment.cicMetaUrl}/areatypes/${area.toLowerCase()}`)
      .pipe(first());
  }
}
