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

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

  requestUrl;
  constructor(
    public http: HttpClient
  ) {
    super('/report/registration/print/setting_testing_room', http)
  }

  getPdfReport(testing_information_uid,academic_year_uid,academic_semester_uid,branch_uid,testing_field_uid,testing_center_uid,from_date,to_date) {
    this.requestUrl = `${this.fullUrl}/${testing_information_uid}/${academic_year_uid}/${academic_semester_uid}/${branch_uid}/${testing_field_uid}/${testing_center_uid}/${from_date}/${to_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,academic_year_uid,academic_semester_uid,branch_uid,testing_field_uid,testing_center_uid,from_date,to_date) {
    this.requestUrl = `${this.fullUrl}/${testing_information_uid}/${academic_year_uid}/${academic_semester_uid}/${branch_uid}/${testing_field_uid}/${testing_center_uid}/${from_date}/${to_date}/xls`;
    window.open(this.requestUrl);
    return this.requestUrl;
  }

  getPdfReport16(subject_uid,testing_information_uid) {
    this.requestUrl = `${environment.storeApi}/api/report/Test/exam_result_subject/${subject_uid}/${testing_information_uid}/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' });
      })
    );
  }

  getExcelReport16(subject_uid,testing_information_uid) {
    this.requestUrl = `${environment.storeApi}/api/report/Test/exam_result_subject/${subject_uid}/${testing_information_uid}/xls`;
    window.open(this.requestUrl);
    return this.requestUrl;
  }

  getPdfReport17(testing_information_uid,academic_year_code,academic_semester_code,branch_uid,testing_center_uid,room_name_th) {
    this.requestUrl = `${environment.storeApi}/api/report/Test/summary_candidates_absentees_passers/${testing_center_uid}/${academic_year_code}/${branch_uid}/${testing_information_uid}/${academic_semester_code}/${room_name_th}/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' });
      })
    );
  }

  getExcelReport17(testing_information_uid,academic_year_code,academic_semester_code,branch_uid,testing_center_uid,room_name_th) {
    this.requestUrl = `${environment.storeApi}/api/report/Test/summary_candidates_absentees_passers/${testing_center_uid}/${academic_year_code}/${branch_uid}/${testing_information_uid}/${academic_semester_code}/${room_name_th}/xls`;
    window.open(this.requestUrl);
    return this.requestUrl;
  }
}
