import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, catchError, throwError } from 'rxjs';


@Injectable({
  providedIn: 'root'
})
export class CepService {
  private readonly baseURL = 'https://viacep.com.br/ws';

  constructor(private readonly http: HttpClient) { }

  buscarCeps(cepURL: string): Observable<any> {
    return this.http.get<any>(`${this.baseURL}/${cepURL}/json`)
      .pipe(
        catchError(error => {
          console.error('Erro ao buscar o CEP:', error);
          return throwError('Ocorreu um erro ao buscar o CEP');
        })
      );
  }
}
