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

@Injectable({
  providedIn: 'root'
})
export class CandidateRegisteredBySubjectService extends BaseService{
  requestUrl;
  constructor(
    public http: HttpClient
  ) {
    super('/report/candidate/print/candidates_registered_by_subject', http)
  }

  getPdfReport(subject_uid,academic_year_uid,academic_semester_uid) {
    this.requestUrl = `${this.fullUrl}/${subject_uid}/${academic_year_uid}/${academic_semester_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' });
      })
    );
  }

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