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

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

  constructor(private _http: HttpClient) { }

  private readonly apiV = 'https://3000-yasmimtcc-3egb2023tcche-jzxp8591avr.ws-us106.gitpod.io';

  getAllPacientes(unidId : number): Observable<any>{
    const url = unidId !== undefined ? `${this.apiV}/unid-saude/${unidId}/paciente` : `${this.apiV}/unid-saude/paciente`;

    return this._http.get<any>(url);
  }

  getPacienteByName(nome: string): Observable<any> {
    const params = new HttpParams().set('nome', nome);
    const url = `${this.apiV}/unid-saude/paciente`;

    return this._http.get<any>(url, { params });
  }

  getAllCids(): Observable<any> {
    return this._http.get(`${this.apiV}/unid-saude/cid`);
  }


  getCidByCode(codigo: string): Observable<any> {
    const params = new HttpParams().set('codigo', codigo);
    return this._http.get<any>(`${this.apiV}/unid-saude/cid`, { params });
  }
}
