import { Injectable } from '@angular/core';
import { HttpRequestService } from '../resources/http-request.service';
import { ResponseDataPostalCode } from 'src/app/interfaces/locate/locate.interface';
import { Observable, map } from 'rxjs';
import { ResponseDataSuburb } from 'src/app/interfaces/acquisition-management/dispatch.interface';

@Injectable({
  providedIn: 'root'
})
export class LocateService {

  private _url: string;
  constructor( private _httpRequestService: HttpRequestService ) {
    this._url = 'country';
  }

  public getDataByPostalCode(postalCode: string): Observable<ResponseDataPostalCode> {
    return this._httpRequestService.getQuery(`${this._url}/postal-code-data/${postalCode}`).pipe(map((data: any) => data))
  }

  public getSuburbByPostalCode(postalCode: string): Observable<ResponseDataSuburb> {
    return this._httpRequestService.getQuery(`${this._url}/suburb-by-postal-code/${postalCode}`).pipe(map((data: any) => data))
  }
}
