import { Injectable } from '@angular/core';
import { Observable ,  Observer } from 'rxjs';
import { ITypeaheadItem } from '../models/typeahead.item';
import { HttpClient, HttpParams } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";

@Injectable({
  providedIn: 'root',
})
export class TypeaheadService {
  constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
  }

  ApiEndpoint() {
    return this.appConfig.getConfig("apiEndPoint");
  }

  getSearchTypeaheadItems(searchText:string,skip = 0,take = 10): Observable<ITypeaheadItem[]> {
    return this.httpClient.get<ITypeaheadItem[]>(`${this.ApiEndpoint()}/api/v1/typeahead/search/?q=${searchText}&skip=${skip}&take=${take}`);
  }

  getTagTypeaheadItems(searchText: string, skip = 0, take = 10): Observable<ITypeaheadItem[]> {
    return this.httpClient.get<ITypeaheadItem[]>(`${this.ApiEndpoint()}/api/v1/typeahead/tag/?q=${searchText}&skip=${skip}&take=${take}`);
  }  

  getCityTypeaheadItems(searchText: string, skip = 0, take = 10): Observable<ITypeaheadItem[]> {
    return this.httpClient.get<ITypeaheadItem[]>(`${this.ApiEndpoint()}/api/v1/typeahead/city/?q=${searchText}&skip=${skip}&take=${take}`);
  }  
}
