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 'src/environments/environment';

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

  getPDF(paymentcode){
    return this.http.get(`https://ru.71dev.com/etest-admin/api/report/print/receipt_by_payment_code/256400052/pdf`);
  }

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

  getPdfReportRealUat(registeruid) {
    // this.requestUrl = `${this.fullUrl}/${registeruid}/pdf`;
    this.requestUrl = `${environment.adminApi}/api/report/print/receipt_form_for_all/${registeruid}/pdf`;
    return this.http.get(this.requestUrl, { responseType: 'blob', observe: 'response'}).pipe(
      map((res: any) => {
        return new Blob([res.body], { type: 'application/pdf' });
      })
    );
  }

  getPdfReportReceiptForAll(registeruid) {
    // this.requestUrl = `${this.fullUrl}/${registeruid}/pdf`;
    this.requestUrl = `${environment.adminApi}/api/report/print/receipt_for_all/${registeruid}/pdf`;
    return this.http.get(this.requestUrl, { responseType: 'blob', observe: 'response'}).pipe(
      map((res: any) => {
        return new Blob([res.body], { type: 'application/pdf' });
      })
    );
  }

  getPdfReportCopy(paymentcode) {
    this.requestUrl = `${environment.adminApi}/api/report/print/receipt_copy_by_payment_code/${paymentcode}/pdf`;
    return this.http.get(this.requestUrl, { responseType: 'blob', observe: 'response'}).pipe(
      map((res: any) => {
        return new Blob([res.body], { type: 'application/pdf' });
      })
    );
  }

  getPdfReportCopyRealUat(registeruid) {
    this.requestUrl = `${environment.adminApi}/api/report/print/receipt_copy_for_all/${registeruid}/pdf`;
    return this.http.get(this.requestUrl, { responseType: 'blob', observe: 'response'}).pipe(
      map((res: any) => {
        return new Blob([res.body], { type: 'application/pdf' });
      })
    );
  }

  // return this.http.get<T>(`${environment.adminApi}/api/v1/register/testing_receipts_paymant/${paymentcode}`);

}
