export class NodeUtilities{static getNodeFromID(t,e){let r=e.find(e=>e.id===t);return r||console.warn(`Node with ID ${t} not found`),r}static getSocketFromID(t,e){for(let r of e){for(let e of r.inputs)if(e.id===t)return e;for(let e of r.outputs)if(e.id===t)return e}}static convertValueTypeToSocketType(t){switch(t.jsonType){case"boolean":return"BOOLEAN";case"number":case"bigint":return"NUMBER";case"string":return"STRING";default:return"ANY"}}static backtrackFrom(t,e){if(!t)throw Error("Collection has to exist");if(!t.nodes)throw Error("Collection has to have existing nodes");if(!t.connections)throw Error("Collection has to have existing connections");let r=this.getNodeFromID(e,t.nodes);if(!r)throw Error("Node has to exist");if(!r.inputs)throw Error("Node has to have existing inputs");if(!r.outputs)throw Error("Node has to have existing outputs");let o=[],i=[];for(let e of r.inputs)i=i.concat(t.connections.filter(t=>t.to===e.id).map(e=>this.getNodeFromID(this.getSocketFromID(e.from,t.nodes).nodeId,t.nodes)));for(let e of i){o.push(e);let r=this.backtrackFrom(t,e.id);o=o.concat(r)}return o}static validate(t){if(!t||!t.nodes||!t.connections)return!1;let e=t.nodes.filter(t=>"OUTPUT"===t.type);if(0===e.length)return!1;for(let r of e){let e=this.backtrackFrom(t,r.id);if(0===e.length||0===e.filter(t=>"INPUT"===t.type).length)return!1}return!0}static add(t,e){return{x:t.x+e.x,y:t.y+e.y}}static subtract(t,e){return{x:t.x-e.x,y:t.y-e.y}}static multiply(t,e){return{x:t.x*e,y:t.y*e}}static lerpNumber(t,e,r){return t*(1-r)+e*r}static lerp(t,e,r){return{x:this.lerpNumber(t.x,e.x,r),y:this.lerpNumber(t.y,e.y,r)}}}