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

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

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