import { Injectable } from '@nestjs/common'; import { FilesService } from '../files/files.service'; import { PrismaService } from '../prisma/prisma.service'; import { SmsConfigService } from '../sms-config/sms-config.service'; import type { AnalyzeImportOptions, CreateImportProfileDto, CreateReportBatchDto, EmbeddedImage, ImportCommitDto, ImportMapping, PagedQuery, ReportBatchInspection, ReportBatchTarget, ReviewImportItemsDto } from './report-materials.contracts'; import { ReportBatchGenerationService } from './batch-generation.service'; import { ReportBatchOperationService } from './batch-operation.service'; import { ReportChannelExportService } from './channel-export.service'; import { ReportImportParserService } from './import-parser.service'; import { ReportImportReviewService } from './import-review.service'; import { ReportOfficialExportService } from './official-export.service'; import { ReportPendingQueryService } from './pending-query.service'; /** Stable compatibility facade; R4 delegates report-material behavior to focused domains. */ @Injectable() export class ReportMaterialsService { private readonly pendingQuery: ReportPendingQueryService; private readonly officialExport: ReportOfficialExportService; private readonly importParser: ReportImportParserService; private readonly importReview: ReportImportReviewService; private readonly batchOperation: ReportBatchOperationService; private readonly channelExport: ReportChannelExportService; private readonly batchGeneration: ReportBatchGenerationService; constructor(prisma: PrismaService, files: FilesService, smsConfig: SmsConfigService) { this.pendingQuery = new ReportPendingQueryService(prisma, files, smsConfig); this.officialExport = new ReportOfficialExportService(prisma, files, smsConfig, this.pendingQuery); this.importParser = new ReportImportParserService(prisma, files, smsConfig); this.importReview = new ReportImportReviewService(prisma, files, smsConfig, this.importParser); this.batchOperation = new ReportBatchOperationService(prisma, files, smsConfig); this.channelExport = new ReportChannelExportService(prisma, files, smsConfig); this.batchGeneration = new ReportBatchGenerationService(prisma, files, smsConfig, this.batchOperation, this.channelExport); } async buildOfficialTemplate(reportType: 'signature' | 'drainage', operatorId?: string) { return this.officialExport.buildOfficialTemplate(reportType, operatorId); } async exportPending(query: { reportType?: 'signature' | 'drainage'; tenantId?: string; applicationId?: string }, operatorId?: string) { return this.officialExport.exportPending(query, operatorId); } async listPending(query: { reportType?: 'signature' | 'drainage'; tenantId?: string; applicationId?: string } & PagedQuery) { return this.pendingQuery.listPending(query); } listImportProfiles(reportType?: 'signature' | 'drainage') { return this.importParser.listImportProfiles(reportType); } async saveImportProfile(data: CreateImportProfileDto) { return this.importParser.saveImportProfile(data); } async analyzeImport(file: { originalname: string; mimetype: string; size: number; buffer: Buffer }, options: AnalyzeImportOptions) { return this.importParser.analyzeImport(file, options); } async commitImport(batchId: string, data: ImportCommitDto) { return this.importReview.commitImport(batchId, data); } async listImportReviewBatches(query: PagedQuery & { reportType?: 'signature' | 'drainage'; status?: string } = {}) { return this.importReview.listImportReviewBatches(query); } async reviewImportItems(batchId: string, data: ReviewImportItemsDto) { return this.importReview.reviewImportItems(batchId, data); } async listBatches(query: PagedQuery = {}) { return this.batchGeneration.listBatches(query); } async createBatch(data: CreateReportBatchDto) { return this.batchGeneration.createBatch(data); } async preflightBatch(data: Pick) { return this.batchGeneration.preflightBatch(data); } }