import {Injectable} from "@angular/core";
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {environment} from "../../../../../environments/environment";
import {Observable} from "rxjs";
import {ComprobanteRetencionDto} from "../model/ComprobanteRetencionDto";
import {DetalleCRetencionDto} from "../model/DetalleCRetencionDto";


@Injectable({
    providedIn: 'root'
})
export class CretencionService {


    constructor(private http: HttpClient) {
    }

    url = `${environment.HOST}/`;
    endpoint: string = 'cretencion';


    saveObject(obj): Observable<any> {
        return this.http.post(this.url + this.endpoint + '/guardarCretencion', obj);
    }

    getAll(): Observable<any> {
        return this.http.get(this.url + this.endpoint + '/listarCretencion');
    }

    getById(key): Observable<any> {
        return this.http.get(this.url + this.endpoint + '/buscarPorIdCretencion/' + key);
    }


    deleteObject(key): Observable<any> {
        return this.http.delete(this.url + this.endpoint + '/eliminarCretencion/' + key);
    }

    getByFecha(key): Observable<any> {
        return this.http.get(this.url + this.endpoint + '/findByFecha/' + key);
    }

    getUpdateXml(comp: ComprobanteRetencionDto): Observable<any> {
        let headers = new HttpHeaders();
        headers.append('content-type', 'application/json');
        headers.append('accept', 'application/json');
        return this.http.post(this.url + this.endpoint + '/genXML' , comp);
    }


    getReporte(idComprobante: number): Observable<any>{
        const httpOptions = {
            responseType: 'arraybuffer' as 'json'
        };
        return this.http.get(this.url + this.endpoint + '/print/' + idComprobante, httpOptions);
    }
}
