import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { environment } from '../../environments/environment';
const FilePath_URL = (id: string = null) => { return `${environment.apiUrl}/Files/${(id ? `${id}` : '')}` }
const FileList_URL = (id: string = null) => { return `${environment.apiUrl}/FileList/${(id ? `${id}` : '')}` }
@Injectable({
  providedIn: 'root'
})
export class FileService {

  constructor(
    private http: HttpClient
  ) { }


  ImageUrl(imagePath: string) {
    return FilePath_URL('Images/' + encodeURI(imagePath));
  }
  FileList(folderPath: string) {
    return this.http.get<string[]>(FileList_URL(folderPath)).pipe(map(response => {
      return response.filter(s => s.indexOf('Thumbs.db') == -1).map(f => f.replace("/", ""));
    }));
  }
}
