import type { InstrumentMethod, InstrumentRunItem, QpcrSample, QpcrTarget, } from './types' import { idFromName } from './builderIdUtils' export function normalizeInstrumentMethod( method: Partial & { name?: string }, fallbackInstrument?: string ): InstrumentMethod { const name = method.name || method.id || 'Default method' return { id: method.id || idFromName(name, 'method-1'), name, instrument: method.instrument ?? fallbackInstrument, acquisitionMode: method.acquisitionMode, metadata: method.metadata ?? {}, } } export function normalizeInstrumentRunItem( item: Partial & { name?: string; sampleId?: string }, defaultMethodId: string, fallbackOrder: number, index: number ): InstrumentRunItem { const kind = item.kind ?? 'sample' const sampleId = item.sampleId || (kind === 'sample' ? idFromName(item.name ?? `Sample ${index + 1}`, `sample-${index + 1}`) : undefined) const label = item.name ?? sampleId ?? kind return { id: item.id || idFromName(label, `${kind}-${index + 1}`), order: item.order ?? fallbackOrder, kind, sampleId, name: item.name, methodId: item.methodId || defaultMethodId, vial: item.vial, plateId: item.plateId, wellId: item.wellId, injectionVolume: item.injectionVolume, expectedDurationMin: item.expectedDurationMin, status: item.status ?? 'planned', metadata: item.metadata ?? {}, } } export function normalizeQpcrSample(sample: QpcrSample): QpcrSample { return { ...sample, metadata: sample.metadata ?? {}, } } export function normalizeQpcrTarget(target: QpcrTarget): QpcrTarget { return { ...target, metadata: target.metadata ?? {}, } }