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 = 'http://localhost/sfcode/backend/filesave.php';

  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({
        username: '',
        filename: 'lambda',
        language: '.cpp',
        text: 'Random Shit',
        path: '/'
      });
    }

    return of(ret);
  }

  upload(file): Observable<any> {
    return this.http.post(this.baseApiUrl, file);
  }

}
