import { ReportFile as PrismaReportFile } from '@prisma/client';
import { ReportFile } from '../../../domain/entities/report-file.entity';
import { OutputFormat } from '../../../domain/value-objects';

export class ReportFileMapper {
  static toDomain(raw: PrismaReportFile): ReportFile {
    return ReportFile.reconstitute({
      id: raw.id,
      snapshotId: raw.snapshotId,
      fileName: raw.fileName,
      filePath: raw.filePath,
      fileUrl: raw.fileUrl,
      fileSize: raw.fileSize,
      fileFormat: raw.fileFormat as OutputFormat,
      mimeType: raw.mimeType,
      downloadCount: raw.downloadCount,
      lastDownloadAt: raw.lastDownloadAt,
      createdAt: raw.createdAt,
      expiresAt: raw.expiresAt,
    });
  }

  static toPersistence(
    domain: ReportFile,
  ): Omit<PrismaReportFile, 'id'> & { id?: bigint } {
    return {
      id: domain.id || undefined,
      snapshotId: domain.snapshotId,
      fileName: domain.fileName,
      filePath: domain.filePath,
      fileUrl: domain.fileUrl,
      fileSize: domain.fileSize,
      fileFormat: domain.fileFormat,
      mimeType: domain.mimeType,
      downloadCount: domain.downloadCount,
      lastDownloadAt: domain.lastDownloadAt,
      createdAt: domain.createdAt,
      expiresAt: domain.expiresAt,
    };
  }
}
