import { HttpClient } from '@angular/common/http'; import { Injectable, inject } from '@angular/core'; import { Observable } from 'rxjs'; import { BatchResult, ConflictStrategy, ImportSourcePayload, ValidationResult } from './api.types'; /** POST /imports/validate (one source, writes nothing) and POST /imports/commit (a batch, one transaction). */ @Injectable({ providedIn: 'root' }) export class ImportsApi { private readonly http = inject(HttpClient); validate(source: ImportSourcePayload): Observable { return this.http.post('/imports/validate', { source }); } /** `mergeDuplicates`: rows of different sources with the same natural key become one record. */ commit(sources: ImportSourcePayload[], onConflict: ConflictStrategy, mergeDuplicates = false): Observable { return this.http.post('/imports/commit', { sources, on_conflict: onConflict, merge_duplicates: mergeDuplicates }); } }