// import { Request, Response } from "express"; // // import assetModel from "../../../shared/model/assets/flooritems-Model.ts"; // import assetModel from "../../../shared/model/builder/assets/asset-Model.ts"; // import actionModel from "../../../shared/model/simulation/actionmodel.ts"; // import triggerModel from "../../../shared/model/simulation/triggersmodel.ts"; // import productFlowModel from "../../../shared/model/simulation/ProductFlowmodel.ts"; // export class productFlowservice { // static async setproductFlow(req: Request, res: Response): Promise { // try { // const { // productName, // modelUuid, // modelName, // eventData, // organization, // productID, // } = req.body; // // Validate required fields // if (!modelUuid || !modelName || !organization) { // return res.status(400).json({ message: "Missing required fields" }); // } // // Check if asset exists // const existingAsset = await assetModel(organization).findOne({ // modelUuid: modelUuid, // isArchive: false, // }); // if (!existingAsset) { // return res.status(404).json({ message: "Asset not found for the ID" }); // } // // Prepare point references // let pointRefs: any[] = []; // if (eventData?.points && Array.isArray(eventData.points)) { // for (const point of eventData.points) { // let actionRefs: any[] = []; // let triggerRefs: any[] = []; // // Process actions // if (Array.isArray(point.actions)) { // for (const action of point.actions) { // const actionDoc = await actionModel(organization).create({ // pointsUUID: point.uuid, // isArchive: false, // uuid: action.uuid, // name: action.name, // type: action.type, // material: action.material || null, // delay: action.delay || null, // spawn_Interval: action.spawn_Interval || null, // }); // actionRefs.push({ // _id: actionDoc._id, // ...action, // }); // } // } // // Process triggers // if (Array.isArray(point.triggers)) { // for (const trigger of point.triggers) { // const triggerDoc = await triggerModel(organization).create({ // pointsUUID: point.uuid, // isArchive: false, // uuid: trigger.uuid, // name: trigger.name, // type: trigger.type, // bufferTime: trigger.bufferTime || null, // }); // triggerRefs.push({ // _id: triggerDoc._id, // ...trigger, // }); // } // } // pointRefs.push({ // pointuuid: point.uuid, // position: point.position || [], // rotation: point.rotation || [], // actions: actionRefs, // triggers: triggerRefs, // connections: point.connections || null, // }); // } // } // // Check if product flow exists // const existingproductData = await productFlowModel(organization).findOne({ // _id: productID, // }); // let result; // if (existingproductData) { // // Update existing product flow // result = await productFlowModel(organization).findOneAndUpdate( // { _id: productID }, // { // $push: { // ProductData: { // AssetName: modelName, // Assetuuid: modelUuid, // paths: { // Points: pointRefs, // }, // isArchive: false, // }, // }, // }, // { new: true } // ); // } else { // // Create new product flow // result = await productFlowModel(organization).create({ // _id: productID, // productName: productName, // ProductData: [ // { // AssetName: modelName, // Assetuuid: modelUuid, // paths: { // Points: pointRefs, // }, // isArchive: false, // }, // ], // eventType: eventData?.type || null, // speed: eventData?.speed || null, // }); // } // res.status(201).json({ // message: "Product flow processed successfully", // data: result, // }); // } catch (error) { // console.error("Error creating flooritems:", error); // res.status(500).json({ message: "Failed to create flooritems" }); // } // } // static async pointActionList(req: Request, res: Response): Promise {} // static async productpathsList(req: Request, res: Response): Promise { // try { // const { organization } = req.params; // const productFlowList = await productFlowModel(organization) // .find() // .select("ProductData productName -_id") // .exec(); // const formattedData = await Promise.all( // productFlowList.map(async (item) => ({ // productName: item.productName, // paths: await Promise.all( // item.ProductData.map(async (data: any) => ({ // Points: await Promise.all( // data.paths.Points.map(async (point: any) => { // const actions = await actionModel(organization) // .find({ _id: { $in: point.actions } }) // .select( // "-_id -pointsUUID -isArchive -createdAt -updatedAt -__v" // ) // .lean(); // const triggers = await triggerModel(organization) // .find({ _id: { $in: point.triggers } }) // .select( // "-_id -pointsUUID -isArchive -createdAt -updatedAt -__v" // ) // .lean(); // return { // connections: point.connections || null, // pointuuid: point.pointuuid, // actions: actions, // triggers: triggers, // position: point.position, // rotation: point.rotation, // }; // }) // ), // })) // ), // })) // ); // return res.status(200).json(formattedData); // } catch (error) { // console.error("Error get flooritems:", error); // res.status(500).json({ error: "Failed to get flooritems" }); // } // } // // static async deleteFloorItems(req: Request, res: Response): Promise { // // try { // // const { modelUuid, modelName, organization } = req.body; // // const findValue = await assetModel(organization).findOneAndDelete({ // // modelUuid: modelUuid, // // modelName: modelName, // // isArchive: false, // // }); // // if (!findValue) { // // res.status(200).json("user not found"); // // } else { // // res.status(201).json(findValue); // // } // // } catch (error) { // // console.error("Error get flooritems:", error); // // res.status(500).json({ error: "Failed to get flooritems" }); // // } // // } // // static async updateAssetPositionRotation( // // req: Request, // // res: Response // // ): Promise { // // try { // // const { // // modelUuid, // // modelName, // // position, // // modelfileID, // // rotation, // // isLocked, // // isVisible, // // organization, // // // eventData, // Optional // // } = req.body; // // const existingAsset = await assetModel(organization).findOne({ // // modelUuid: modelUuid, // // isArchive: false, // // }); // // if (!existingAsset) return res.send("Asset not found"); // // const updateAsset = await assetModel(organization).updateMany( // // { modelUuid: modelUuid, modelName: modelName, isArchive: false }, // // { // // position: position, // // rotation: rotation, // // isVisible: isVisible, // // isLocked: isLocked, // // } // // ); // // if (updateAsset) // // return res.status(200).json({ message: "Asset updated successfully" }); // // } catch (error: any) { // // return res.send(error.message); // // } // // } // // static async updateActionsDatas(req: Request, res: Response) {} // }