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 CandidateService extends BaseService {
  requestUrl;
  constructor(
    public http: HttpClient
  ) {
    super('/report/candidate/print/application', http)
  }

  getPdfReport(informationUid, academicyearUid, academicsemesterUid, fromdate, todate) {
    // console.log(this.fullUrl);
    this.requestUrl = `${this.fullUrl}/${informationUid}/${academicyearUid}/${academicsemesterUid}/${fromdate}/${todate}/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(informationUid, academicyearUid, academicsemesterUid, fromdate, todate) {
    this.requestUrl = `${this.fullUrl}/${informationUid}/${academicyearUid}/${academicsemesterUid}/${fromdate}/${todate}/xls`;
    window.open(this.requestUrl);
    return this.requestUrl;
  }
}
