[
    {
        "id": "a58e1e6820201c49",
        "type": "subflow",
        "name": "Get Loss Reasons from MIP",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 40,
                "y": 160,
                "wires": [
                    {
                        "id": "07fc8c6b54dfd52b"
                    },
                    {
                        "id": "b6b14e515cc07c4f"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1820,
                "y": 180,
                "wires": [
                    {
                        "id": "7103451a05d2216e",
                        "port": 0
                    },
                    {
                        "id": "b7973ee83f2ec2a7",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "7103451a05d2216e",
        "type": "change",
        "z": "a58e1e6820201c49",
        "name": "Mapping loss reason attributes",
        "rules": [
            {
                "t": "set",
                "p": "title-de",
                "pt": "msg",
                "to": "payload.obj[\"reasontext.text\"]",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "title-en",
                "pt": "msg",
                "to": "payload.obj[\"reasontext.text\"]",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "title-it",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "title-ro",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "title-cz",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "valid-from",
                "pt": "msg",
                "to": "2021-01-01",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "classification",
                "pt": "msg",
                "to": "technical",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tags",
                "pt": "msg",
                "to": "[]",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "color",
                "pt": "msg",
                "to": "purple",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "icon",
                "pt": "msg",
                "to": "alarm-exclamation",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "mode",
                "pt": "msg",
                "to": "quality",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "target-minutes",
                "pt": "msg",
                "to": "0",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "reduces-oee",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "changes-product",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "input-rejects",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "ignore-units",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "parent-loss-reason-title",
                "pt": "msg",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1610,
        "y": 120,
        "wires": [
            []
        ]
    },
    {
        "id": "31146f770a1e7a20",
        "type": "http request",
        "z": "a58e1e6820201c49",
        "name": "service call to MIP",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 390,
        "y": 120,
        "wires": [
            [
                "6ed829c29834a705"
            ]
        ]
    },
    {
        "id": "07fc8c6b54dfd52b",
        "type": "function",
        "z": "a58e1e6820201c49",
        "name": "build request",
        "func": "msg.payload = { \n    \"params\": [], \n    \"columns\": [        \n        \"reason.id\", \n        \"reason.article\", \n        \"reason.type\",\n        \"reasontext.text\",\n        \"reason.workplace\",\n        \"reason.textno\"], \n    \"returnAsObject\": true,\n    \"languageKey\": \"en\"\n}\n\nmsg.url = msg.baseUrl + \"/data/MDReason/list?X-Access-Id=\" + msg.xAccessId\n\nlet basic_encrypted = \"Basic \" + new Buffer(msg.user + ':' + msg.password).toString('base64')\n\nmsg.headers = { \n    \"Content-Type\": \"application/json\",\n    \"Authorization\": basic_encrypted\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 190,
        "y": 120,
        "wires": [
            [
                "31146f770a1e7a20"
            ]
        ]
    },
    {
        "id": "5eecf565f833ad95",
        "type": "change",
        "z": "a58e1e6820201c49",
        "name": "Delete META data",
        "rules": [
            {
                "t": "delete",
                "p": "payload[0]",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 870,
        "y": 120,
        "wires": [
            [
                "c0c472d5b2e729b6"
            ]
        ]
    },
    {
        "id": "ae7ff7cfe6826128",
        "type": "split",
        "z": "a58e1e6820201c49",
        "name": "split each reason",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 1310,
        "y": 120,
        "wires": [
            [
                "7103451a05d2216e"
            ]
        ]
    },
    {
        "id": "c0c472d5b2e729b6",
        "type": "function",
        "z": "a58e1e6820201c49",
        "name": "filter scrap reasons",
        "func": "let filteredArray = msg.payload.filter(item => item.obj[\"reason.type\"] === \"A\");\nmsg.payload = filteredArray\n\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1090,
        "y": 120,
        "wires": [
            [
                "ae7ff7cfe6826128"
            ]
        ]
    },
    {
        "id": "6ed829c29834a705",
        "type": "change",
        "z": "a58e1e6820201c49",
        "name": "Clean up for next requests",
        "rules": [
            {
                "t": "delete",
                "p": "headers",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "url",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 640,
        "y": 120,
        "wires": [
            [
                "5eecf565f833ad95"
            ]
        ]
    },
    {
        "id": "25826e2142119889",
        "type": "comment",
        "z": "a58e1e6820201c49",
        "name": "Quality Loss reasons",
        "info": "",
        "x": 210,
        "y": 80,
        "wires": []
    },
    {
        "id": "c833ab2194264a89",
        "type": "http request",
        "z": "a58e1e6820201c49",
        "name": "service call to MIP",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 390,
        "y": 220,
        "wires": [
            [
                "e95ce2ae229dc962"
            ]
        ]
    },
    {
        "id": "b6b14e515cc07c4f",
        "type": "function",
        "z": "a58e1e6820201c49",
        "name": "build request",
        "func": "msg.payload = { \n    \"params\": [], \n    \"columns\": [], \n    \"returnAsObject\": true,\n    \"languageKey\": \"en\"\n}\n\nmsg.url = msg.baseUrl + \"/data/MDStatusText/list?X-Access-Id=\" + msg.xAccessId\n\nlet basic_encrypted = \"Basic \" + new Buffer(msg.user + ':' + msg.password).toString('base64')\n\nmsg.headers = { \n    \"Content-Type\": \"application/json\",\n    \"Authorization\": basic_encrypted\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 190,
        "y": 220,
        "wires": [
            [
                "c833ab2194264a89"
            ]
        ]
    },
    {
        "id": "e95ce2ae229dc962",
        "type": "change",
        "z": "a58e1e6820201c49",
        "name": "Clean up for next requests",
        "rules": [
            {
                "t": "delete",
                "p": "headers",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "url",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 640,
        "y": 220,
        "wires": [
            [
                "559fc5699b19c3d6"
            ]
        ]
    },
    {
        "id": "559fc5699b19c3d6",
        "type": "change",
        "z": "a58e1e6820201c49",
        "name": "Delete META data",
        "rules": [
            {
                "t": "delete",
                "p": "payload[0]",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 870,
        "y": 220,
        "wires": [
            [
                "cb9b93773da7a82a"
            ]
        ]
    },
    {
        "id": "d18b12c87c2aeb2d",
        "type": "comment",
        "z": "a58e1e6820201c49",
        "name": "Availability Loss reasons StatusText?",
        "info": "",
        "x": 270,
        "y": 180,
        "wires": []
    },
    {
        "id": "b7973ee83f2ec2a7",
        "type": "change",
        "z": "a58e1e6820201c49",
        "name": "Mapping loss reason attributes",
        "rules": [
            {
                "t": "set",
                "p": "title-de",
                "pt": "msg",
                "to": "payload.obj[\"statustext.text\"]",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "title-en",
                "pt": "msg",
                "to": "payload.obj[\"statustext.text\"]",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "title-it",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "title-ro",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "title-cz",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "valid-from",
                "pt": "msg",
                "to": "2021-01-01",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "classification",
                "pt": "msg",
                "to": "technical",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tags",
                "pt": "msg",
                "to": "[]",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "color",
                "pt": "msg",
                "to": "red",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "icon",
                "pt": "msg",
                "to": "alarm-exclamation",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "mode",
                "pt": "msg",
                "to": "availability",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "target-minutes",
                "pt": "msg",
                "to": "0",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "reduces-oee",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "changes-product",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "input-rejects",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "ignore-units",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "parent-loss-reason-title",
                "pt": "msg",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1350,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "cb9b93773da7a82a",
        "type": "split",
        "z": "a58e1e6820201c49",
        "name": "split each reason",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 1090,
        "y": 220,
        "wires": [
            [
                "b7973ee83f2ec2a7"
            ]
        ]
    },
    {
        "id": "87fc67442f9080e5",
        "type": "subflow",
        "name": "Patch loss reason",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 300,
                "y": 260,
                "wires": [
                    {
                        "id": "07058fae669a1665"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1000,
                "y": 260,
                "wires": [
                    {
                        "id": "a2d7b0882820171f",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "a2d7b0882820171f",
        "type": "http request",
        "z": "87fc67442f9080e5",
        "name": "Patch loss reason",
        "method": "use",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://api.oee.ai/loss-reasons/{{{oldLossReasonId}}}",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 770,
        "y": 260,
        "wires": [
            []
        ]
    },
    {
        "id": "07058fae669a1665",
        "type": "function",
        "z": "87fc67442f9080e5",
        "name": "Formatting json payload",
        "func": "msg.headers = {\n    \"Content-Type\": \"application/vnd.api+json\",\n    \"Authorization\": \"Bearer \" + msg.bearerToken\n};\n\nmsg.method = \"PATCH\";\n\nmsg.payload = {\n    \"data\": {\n        \"type\": \"loss-reasons\",\n        \"id\": msg.oldLossReasonId,\n        \"attributes\": {\n            \"title-de\": msg[\"title-de\"],\n            \"title-en\": msg[\"title-en\"],\n            \"title-it\": msg[\"title-it\"],\n            \"title-ro\": msg[\"title-ro\"],\n            \"title-cz\": msg[\"title-cz\"],\n            \"valid-from\": msg[\"valid-from\"],\n            \"valid-to\": msg[\"valid-to\"],\n            \"classification\": msg.classification,\n            \"tags\": msg.tags,\n            \"color\": msg.color,\n            \"icon\": msg.icon,\n            \"mode\": msg.mode,\n            \"target-minutes\": msg[\"target-minutes\"],\n            \"reduces-oee\": msg[\"reduces-oee\"],\n            \"changes-product\": msg[\"changes-product\"],\n            \"input-rejects\": msg[\"input-rejects\"],\n            \"ignore-units\": msg[\"ignore-units\"]\n        },\n        \"relationships\": {\n            \"location\": {\n                \"data\": {\n                    \"type\": \"locations\",\n                    \"id\": msg.location\n                }\n            },\n            \"parent-loss-reason\":{\n                \"data\": null\n            }\n        }\n    }\n};\n\nif (msg[\"parent-loss-reason\"]) {\n    msg.payload.data.relationships[\"parent-loss-reason\"].data = {\n            \"type\": \"loss-reasons\",\n            \"id\": msg[\"parent-loss-reason\"]\n        };\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 260,
        "wires": [
            [
                "a2d7b0882820171f"
            ]
        ]
    },
    {
        "id": "a312a6fc64b9406a",
        "type": "subflow",
        "name": "Post loss reason",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 400,
                "y": 260,
                "wires": [
                    {
                        "id": "b269a642d49879ba"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 900,
                "y": 260,
                "wires": [
                    {
                        "id": "3373fbee81df867c",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "b269a642d49879ba",
        "type": "function",
        "z": "a312a6fc64b9406a",
        "name": "Formatting json payload",
        "func": "msg.headers = {\n    \"Authorization\": \"Bearer \" + msg.bearerToken,\n    \"Content-Type\": \"application/vnd.api+json\"\n};\n\nmsg.payload = {\n    \"data\": {\n        \"type\": \"loss-reasons\",\n        \"attributes\": {\n            \"title-de\": msg[\"title-de\"],\n            \"title-en\": msg[\"title-en\"],\n            \"title-it\": msg[\"title-it\"],\n            \"title-ro\": msg[\"title-ro\"],\n            \"title-cz\": msg[\"title-cz\"],\n            \"valid-from\": msg[\"valid-from\"],\n            \"valid-to\": msg[\"valid-to\"],\n            \"classification\": msg.classification,\n            \"tags\": msg.tags,\n            \"color\": msg.color,\n            \"icon\": msg.icon,\n            \"mode\": msg.mode,\n            \"target-minutes\": msg[\"target-minutes\"],\n            \"reduces-oee\": msg[\"reduces-oee\"],\n            \"changes-product\": msg[\"changes-product\"],\n            \"input-rejects\": msg[\"input-rejects\"],\n            \"ignore-units\": msg[\"ignore-units\"]\n        },\n        \"relationships\": {\n            \"location\": {\n                \"data\": {\n                    \"type\": \"locations\",\n                    \"id\": msg.location\n                }\n            }\n        }\n    }\n};\n\nif (msg[\"parent-loss-reason\"]){\n    msg.payload.data.relationships[\"parent-loss-reason\"] = {\n        \"data\": {\n            \"type\": \"loss-reasons\",\n            \"id\": msg[\"parent-loss-reason\"]\n        }\n    };\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 260,
        "wires": [
            [
                "3373fbee81df867c"
            ]
        ]
    },
    {
        "id": "3373fbee81df867c",
        "type": "http request",
        "z": "a312a6fc64b9406a",
        "name": "POST loss reason",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://api.oee.ai/loss-reasons",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 770,
        "y": 260,
        "wires": [
            []
        ]
    },
    {
        "id": "184cc4064c28bc4e",
        "type": "subflow",
        "name": "Get all loss reasons",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 180,
                "y": 280,
                "wires": [
                    {
                        "id": "08143ffcbe9f937c"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1620,
                "y": 280,
                "wires": [
                    {
                        "id": "f59336dfb3d4af2c",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "9a567b3c853a51ea",
        "type": "change",
        "z": "184cc4064c28bc4e",
        "name": "Delete response header",
        "rules": [
            {
                "t": "delete",
                "p": "headers",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1170,
        "y": 280,
        "wires": [
            [
                "f59336dfb3d4af2c"
            ]
        ]
    },
    {
        "id": "08143ffcbe9f937c",
        "type": "function",
        "z": "184cc4064c28bc4e",
        "name": "Set Authorization header",
        "func": "msg.headers = {\n    \"Authorization\": \"Bearer \" + msg.bearerToken\n};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 330,
        "y": 280,
        "wires": [
            [
                "9be5407c3b0330ee"
            ]
        ]
    },
    {
        "id": "1045703e96def829",
        "type": "http request",
        "z": "184cc4064c28bc4e",
        "name": "GET all loss-reasons",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://api.oee.ai/loss-reasons?filter[location]={{{location}}}&filter[valid-at]={{{today}}}",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 920,
        "y": 280,
        "wires": [
            [
                "9a567b3c853a51ea"
            ]
        ]
    },
    {
        "id": "f59336dfb3d4af2c",
        "type": "change",
        "z": "184cc4064c28bc4e",
        "name": "Save all loss reasons",
        "rules": [
            {
                "t": "set",
                "p": "all-loss-reasons",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1440,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "9be5407c3b0330ee",
        "type": "function",
        "z": "184cc4064c28bc4e",
        "name": "Generate iso8601 date for today",
        "func": "msg.today = new Date().toISOString();\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 610,
        "y": 280,
        "wires": [
            [
                "1045703e96def829"
            ]
        ]
    },
    {
        "id": "3eaf2cca52ce5808",
        "type": "subflow",
        "name": "Send loss reasons to oee.ai",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 300,
                "y": 360,
                "wires": [
                    {
                        "id": "d8afcc01e4658d10"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "8807c315f7441134",
        "type": "switch",
        "z": "3eaf2cca52ce5808",
        "name": "Has parent loss reason",
        "property": "parent-loss-reason-title",
        "propertyType": "msg",
        "rules": [
            {
                "t": "nempty"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 690,
        "y": 360,
        "wires": [
            [
                "3f83b636f48f77d9"
            ],
            [
                "6ec87b6a5061674a"
            ]
        ]
    },
    {
        "id": "d8afcc01e4658d10",
        "type": "subflow:184cc4064c28bc4e",
        "z": "3eaf2cca52ce5808",
        "name": "",
        "x": 450,
        "y": 360,
        "wires": [
            [
                "8807c315f7441134"
            ]
        ]
    },
    {
        "id": "17c1dc97ca31b6f8",
        "type": "subflow:a312a6fc64b9406a",
        "z": "3eaf2cca52ce5808",
        "name": "",
        "x": 1790,
        "y": 380,
        "wires": [
            [
                "cd8f592940a5dd61"
            ]
        ]
    },
    {
        "id": "6ec87b6a5061674a",
        "type": "function",
        "z": "3eaf2cca52ce5808",
        "name": "Check if loss reason already exists",
        "func": "// replace data=null if there is no parent loss reason with an id attribute of null\nlet match = msg[\"all-loss-reasons\"].data.find(({ relationships, attributes }) => {\n    const parentId = relationships[\"parent-loss-reason\"].data?.id;\n    // trim whitespaces in the middle and on the end just like oee.ai does\n    const isMatchingTitle = [\"title-de\", \"title-en\", \"title-it\", \"title-ro\", \"title-cz\"].some(lang => attributes[lang] === msg[lang].replace(/\\s+/g,' ').trim());\n    return parentId === msg[\"parent-loss-reason\"] && isMatchingTitle;\n});\n\n\nfunction compareProperties(a, b, properties) {\n  return properties.every(prop => {\n      if (prop == 'target-minutes'){\n        if (parseFloat(a[prop]) == parseFloat(b[prop])){\n            return true;\n        }else{\n            return false;\n        }\n      }else{\n        if(a[prop] == b[prop]){\n            return true;\n        }else{\n            return false;\n        }\n        \n      }});\n}\n\nif (match){\n    let propertiesToCompare = [\n    'classification',\n    'color',\n    'icon',\n    'mode',\n    'target-minutes',\n    'reduces-oee',\n    'changes-product',\n    'input-rejects',\n    'ignore-units',\n    ];\n\n    if (!compareProperties(match[\"attributes\"], msg, propertiesToCompare)) {\n        return [msg, null];\n    }else{\n        return null;\n    }\n}\n\nreturn [null, msg];\n\n",
        "outputs": 2,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1380,
        "y": 360,
        "wires": [
            [
                "e36450a6aa0fe7e7"
            ],
            [
                "17c1dc97ca31b6f8"
            ]
        ]
    },
    {
        "id": "e36450a6aa0fe7e7",
        "type": "subflow:87fc67442f9080e5",
        "z": "3eaf2cca52ce5808",
        "name": "",
        "x": 1790,
        "y": 300,
        "wires": [
            [
                "b7ae663e1a23236a"
            ]
        ]
    },
    {
        "id": "b7ae663e1a23236a",
        "type": "debug",
        "z": "3eaf2cca52ce5808",
        "name": "Response from oee.ai",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 2100,
        "y": 340,
        "wires": []
    },
    {
        "id": "3f83b636f48f77d9",
        "type": "function",
        "z": "3eaf2cca52ce5808",
        "name": "Check if parent loss reason title exists",
        "func": "let parent = msg[\"all-loss-reasons\"].data.find(reason => reason.attributes.title == msg[\"parent-loss-reason-title\"]);\n\nif (parent){\n    msg[\"parent-loss-reason\"] = parent.id\n    return msg;\n}\n\nnode.warn(\"Parent loss reason with title \" + msg[\"parent-loss-reason-title\"] + \" does not exist.\");\nreturn null;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1050,
        "y": 300,
        "wires": [
            [
                "6ec87b6a5061674a"
            ]
        ]
    },
    {
        "id": "cd8f592940a5dd61",
        "type": "debug",
        "z": "3eaf2cca52ce5808",
        "name": "Post Loss Reason",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 2070,
        "y": 420,
        "wires": []
    },
    {
        "id": "0246bd7e4768a9e3",
        "type": "tab",
        "label": "MIP synchronizing loss reasons",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "a0cc0d031958f91a",
        "type": "change",
        "z": "0246bd7e4768a9e3",
        "name": "Set API Token",
        "rules": [
            {
                "t": "set",
                "p": "bearerToken",
                "pt": "msg",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 980,
        "y": 140,
        "wires": [
            [
                "28ac72dee746f85c"
            ]
        ]
    },
    {
        "id": "28ac72dee746f85c",
        "type": "subflow:3eaf2cca52ce5808",
        "z": "0246bd7e4768a9e3",
        "name": "",
        "x": 1200,
        "y": 140,
        "wires": []
    },
    {
        "id": "9229733eddddf7ef",
        "type": "inject",
        "z": "0246bd7e4768a9e3",
        "name": "Once a day",
        "props": [],
        "repeat": "86400",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 150,
        "y": 140,
        "wires": [
            [
                "c83e4c0b9cc703b6"
            ]
        ]
    },
    {
        "id": "c83e4c0b9cc703b6",
        "type": "change",
        "z": "0246bd7e4768a9e3",
        "name": "set settings",
        "rules": [
            {
                "t": "set",
                "p": "baseUrl",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "user",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "password",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "xAccessId",
                "pt": "msg",
                "to": "",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "languageKey",
                "pt": "msg",
                "to": "en",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 330,
        "y": 140,
        "wires": [
            [
                "7c09544a0baa8860"
            ]
        ]
    },
    {
        "id": "7c09544a0baa8860",
        "type": "subflow:a58e1e6820201c49",
        "z": "0246bd7e4768a9e3",
        "name": "",
        "x": 540,
        "y": 140,
        "wires": [
            [
                "156ecf2c5d1cfd4e"
            ]
        ]
    },
    {
        "id": "156ecf2c5d1cfd4e",
        "type": "change",
        "z": "0246bd7e4768a9e3",
        "name": "Set location id",
        "rules": [
            {
                "t": "set",
                "p": "location",
                "pt": "msg",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 140,
        "wires": [
            [
                "a0cc0d031958f91a"
            ]
        ]
    },
    {
        "id": "25214bd5b523c7fa",
        "type": "comment",
        "z": "0246bd7e4768a9e3",
        "name": "^^ configure settings",
        "info": "",
        "x": 360,
        "y": 180,
        "wires": []
    },
    {
        "id": "8fabe22331d6cba2",
        "type": "comment",
        "z": "0246bd7e4768a9e3",
        "name": "^^ set location id",
        "info": "",
        "x": 780,
        "y": 180,
        "wires": []
    },
    {
        "id": "1a792319f951ab60",
        "type": "comment",
        "z": "0246bd7e4768a9e3",
        "name": "^^ enter your oee.ai API token",
        "info": "",
        "x": 1020,
        "y": 180,
        "wires": []
    }
]