import { Injectable } from '@angular/core';
import { SearchService, ItemDTO } from '@swagger/cat';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class RecommandationService {
  constructor(private searchService: SearchService) {}

  public getRecommandations(processId: number, digId: number): Observable<ItemDTO[]> {
    const params = <SearchService.SearchGetRecommendationsParams>{
      sessionId: processId + '',
      digId: digId + '',
    };
    return this.searchService.SearchGetRecommendations(params).pipe(
      map((response) => {
        if (response.error) {
          console.error(response.message);
        }
        return response.result;
      })
    );
  }
}
