import { Injectable } from '@angular/core';
import { File } from './file';
import { Observable, of } from 'rxjs';
import { HttpClient } from '@angular/common/http';


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

  baseApiUrl = "https://file.io";

  constructor(private http: HttpClient) { }

  getFiles(): Observable<File[]> {

    const ret: File[] = [];

    const arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

    for (const item of arr) {
      ret.push({
        id: item,
        filename: "lambda",
        language: "cpp/py/java",
        text: "Random Shit",
      });
    }

    return of(ret);
  }

  upload(file):Observable<any> { 

    const formData = new FormData(); 
    formData.append("file", file, file.name); 
    return this.http.post(this.baseApiUrl, formData) 
  }

}
