import {Injectable} from '@angular/core';
import {HttpService} from './http.service';
import {saveAs} from 'file-saver';

@Injectable()
export class CommonService {

    constructor(private httpService: HttpService) {

    }

    /**
     * Returns xmas contact list pdf
     * @param type
     */
    public apiExportContactsPdf(filename: string, type: string): void {
        const formData = new FormData();
        formData.append('type', type);
        this.httpService.apiFilePost('export-contacts-pdf', formData).subscribe(
            data => {
                saveAs(new Blob([data], {type: 'pdf'}), filename + '.pdf');
            },
            error => {
            }
        );
    }

    /**
     * Returns xmas contact list pdf
     * @param filename
     * @param type
     */
    public apiExportXmasPdf(filename: string, type: string): void {
        const formData = new FormData();
        formData.append('type', type);
        this.httpService.apiFilePost('create-xmas-pdf', formData).subscribe(
            data => {
                saveAs(new Blob([data], {type: 'pdf'}), filename + '.pdf');
            },
            error => {
            }
        );
    }
}
