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 SeparatedByExamCenterService extends BaseService {

  requestUrl;
  constructor(
    public http: HttpClient
  ) {
    super('/report//Test/separated_by_exam_center', http)
    super.fullUrl = `${environment.storeApi}/api/report/Test/separated_by_exam_center`
  }

  getPdfReport(testing_information_uid, subject_uid, branch_uid,start_date,end_date) {
    this.requestUrl = `${this.fullUrl}/${testing_information_uid}/${subject_uid}/${branch_uid}/${start_date}/${end_date}/pdf`;
    console.log(this.requestUrl);
    return this.http.get(this.requestUrl, { responseType: 'blob', observe: 'response'}).pipe(
      map((res: any) => {
        return new Blob([res.body], { type: 'application/pdf' });
      })
    );
  }

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