import type { RailDeckDirectIntegrationClient as Client } from '@raildeck/frontend-sdk/direct-integration'; /** * Read a formation and its driving settings for review. * @param client - Configured client; the caller owns current authority. * @param accountId - Authorised account for this workflow. * @param trainId - Explicitly selected saved train. * @param signal - Caller-owned cancellation signal. * @returns The saved train and original settings revision. */ export async function openSavedTrain( client: Client, accountId: string, trainId: string, signal: AbortSignal, ) { const options = { signal, timeoutMs: 15_000 }; const train = await client.trainFormations.get(accountId, trainId, options); const settings = await client.trainFormations.getDrivingSettings(accountId, trainId, options); return { train, settings }; } /** * Change a confirmed saved style while retaining reviewed handling and revision. * @param client - Configured client; the caller owns current authority. * @param accountId - Authorised account for this workflow. * @param trainId - Explicitly selected saved train. * @param opened - Record retained from the review that authorised this change. * @param style - Driving style explicitly chosen for the saved train. * @returns Saved settings; saving them does not restart a moving train. */ export async function saveReviewedTrainStyle( client: Client, accountId: string, trainId: string, opened: Awaited>, style: Parameters[2]['style'], ) { return client.trainFormations.saveDrivingSettings(accountId, trainId, { expectedRevision: opened.revision, style, handling: opened.handling, }); }