import { Injectable } from '@angular/core';
import { GenericService } from '@iqser/common-ui';
import { HeadersConfiguration } from '@iqser/common-ui/lib/utils';

@Injectable({ providedIn: 'root' })
export class RedactionImportService extends GenericService<void> {
    protected readonly _defaultModelPath = 'import-redactions';

    importRedactions(dossierId: string, fileId: string, file: Blob, pagesToImport: Set<number> | null) {
        const formParams = new FormData();

        if (file !== undefined) {
            formParams.append('file', file);
        }

        if (pagesToImport) {
            formParams.append('pageInclusionRequest', Array.from(pagesToImport).toString());
        }

        const headers = HeadersConfiguration.getHeaders({ contentType: false }).append('ngsw-bypass', 'true');

        return this._http.post<void>(`/${this._serviceName}/${this._defaultModelPath}/${dossierId}/${fileId}`, formParams, {
            headers,
            observe: 'response',
        });
    }
}
