import { Action, Configuration, SlotItem, Slot as ConfigurationSlot, Step as ConfigurationStep, } from "../types/Configuration"; import { AOP, ServiceAction, Slot, Step } from "../types/AOP"; import "react-native-get-random-values"; import { v4 as uuid } from "uuid"; const actionCreator = (action?: Action) => { return action ? { ...action, actionId: uuid(), captureType: action.sourceType === "Ricoh" ? "Image" : action.captureType, } : undefined; }; const slotItemCreator = (slotItem: SlotItem) => { return Object.assign( {}, { ...slotItem, slotItemId: uuid(), isComplete: false, isUploaded: false, availableActions: slotItem.availableActions.map((action) => Object.assign( {}, { actionId: uuid(), actionData: undefined, storagePath: undefined, ...action, } ) ), } ); }; const slotCreator = (slot: ConfigurationSlot) => { return { ...slot, postprocessingServices: slot.postprocessingServices && slot.postprocessingServices.length > 0 ? slot.postprocessingServices.map( (service) => Object.assign( {}, { ...service, status: "idle", } ) as ServiceAction ) : [], slotId: uuid(), isUploaded: false, uploadURL: undefined, uploadURI: undefined, slotType: slot.slotType ? slot.slotType : "DEFAULT", locked: slot.slotType !== "DEFAULT" && slot.refKey !== undefined, slotItems: slot.slotItems ? slot.slotItems.map((slotItem) => slotItemCreator(slotItem)) : [], action: actionCreator(slot.action), isComplete: false, } as Slot; }; const stepCreator = (step: ConfigurationStep) => { const slots = step.slots.map((slot) => slotCreator(slot)); return { ...step, stepType: slots.find( (slot) => slot.slotType === "IMPERFECTION" || slot.slotType === "FEATURE" ) ? "NOT_DEFAULT" : "DEFAULT", slots, stepId: uuid(), isComplete: false, isUploaded: false, } as Step; }; export default function configurationToAopConverter( configuration: Configuration ): AOP { const steps = configuration.steps.map((step) => stepCreator(step)); const aop = { title: configuration.title, steps, gpt: configuration.steps.map((step) => step.slots.map((_) => [])), }; return aop; }