import type { CoreOutcome } from '@faunosteo/core-wasm' import type { MoveDirection, NewReportDraft, Report, SheetRef, Vertebra, VertebraAction, } from '@faunosteo/core-wasm/types' import { coreRuntime } from './runtime' /** * The report rules that need no sheet (R2): creation and the observation list operations * of the store, the vertebra picker's selection. Ids and time come from the caller. */ function run(op: string, input: unknown): CoreOutcome { return coreRuntime().call(op, JSON.stringify(input)) } export interface NewReportInput { draft: NewReportDraft sheet: SheetRef id: string createdAt: string /** Id of the empty observation a draft without any starts with. */ observationId: string } export const reportOps = { newReport: (input: NewReportInput): CoreOutcome => run('report.new', input), addObservation: (report: Report, id: string): CoreOutcome => run('report.add_observation', { report, id }), removeObservation: (report: Report, index: number): CoreOutcome => run('report.remove_observation', { report, index }), moveObservation: ( report: Report, index: number, direction: MoveDirection, ): CoreOutcome => run('report.move_observation', { report, index, direction }), selectVertebrae: ( selection: readonly Vertebra[], action: VertebraAction, ): CoreOutcome => run('vertebra.select', { selection, action }), }