import { HttpClient, HttpEventType } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { BaseService } from '../../base/base-service';

@Injectable({
    providedIn: 'root'
})
export class StudentUploadService extends BaseService {

    constructor(
        public http: HttpClient
    ) {
        super('/v1/student/upload',http)
     }

    // uploadStudent<HttpHeaderResponse>(target: FormData,uid){
    //         return this.http.post(`${this.fullUrl}/${uid}`,target,{
    //                 reportProgress: true,
    //                 observe:'events'
    //         }).pipe(
    //                 map((event) => {
    //                         switch(event.type){
    //                                 case HttpEventType.UploadProgress:
    //                                         const progress = Math.round(100 * event.loaded / event.total);
    //                                         return { status: 'progress', message: `${progress}` };
    //                                 case HttpEventType.Response:
    //                                         return { status: 'success', message:    event.body };
    //                                 default:
    //                                         return `Unhandled event: ${event.type}`;
    //                                 }
    //                         }
    //                 ),
    //                 catchError(err => {
    //                         return of({ status: 'error', message:    `${err.message}` })
    //                 })
    //        )
    // }

    uploadStudent(target: FormData,uid){
        return    this.http.post(`${this.fullUrl}/${uid}`,target)
    }

    uploadStudentWord(target: FormData,uid){
        return    this.http.post(`${this.fullUrl}_word/${uid}`,target)
    }
}
