import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {BaseService} from '../../../base/base-service';
import {map} from 'rxjs/operators';
import {environment} from '../../../../../environments/environment';

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

  requestUrl;
  constructor(
    public http: HttpClient
  ) {
    super('/report//Test/exam_result_subject', http)
    super.fullUrl = `${environment.storeApi}/api/report/Test/exam_result_subject`
  }
  // ${this.fullUrl}
  getPdfReport(subject_uid,testing_information_uid,period_id,test_date) {
    this.requestUrl = `${this.fullUrl}/${period_id}/${test_date}/${subject_uid}/${testing_information_uid}/pdf`;
    return this.http.get(this.requestUrl, { responseType: 'blob', observe: 'response'}).pipe(
      map((res: any) => {
        return new Blob([res.body], { type: 'application/pdf' });
      })
    );
  }

  getExcelReport(subject_uid,testing_information_uid,period_id,test_date){
    this.requestUrl = `${this.fullUrl}/${period_id}/${test_date}/${subject_uid}/${testing_information_uid}/xls`;
    window.open(this.requestUrl);
    return this.requestUrl;
  }
}
