// =======================================================================
// LOGIKKISTE - SPS MULTI-LOGIK (3-FACH & 4-FACH UND/ODER)
// =======================================================================

Blockly.defineBlocksWithJsonArray([
    // --- 3-FACH UND ---
    {
        "type": "ard_logic_and_3",
        "message0": "UND (3-fach) %1 %2 %3",
        "args0": [
            {"type": "input_value", "name": "A"},
            {"type": "input_value", "name": "B"},
            {"type": "input_value", "name": "C"}
        ],
        "inputsInline": false,
        "output": null,
        "colour": 230,
        "tooltip": "Prüft ob ALLE 3 Bedingungen wahr sind (SPS-Style)."
    },

    // --- 4-FACH UND ---
    {
        "type": "ard_logic_and_4",
        "message0": "UND (4-fach) %1 %2 %3 %4",
        "args0": [
            {"type": "input_value", "name": "A"},
            {"type": "input_value", "name": "B"},
            {"type": "input_value", "name": "C"},
            {"type": "input_value", "name": "D"}
        ],
        "inputsInline": false,
        "output": null,
        "colour": 230,
        "tooltip": "Prüft ob ALLE 4 Bedingungen wahr sind (SPS-Style)."
    },

    // --- 3-FACH ODER ---
    {
        "type": "ard_logic_or_3",
        "message0": "ODER (3-fach) %1 %2 %3",
        "args0": [
            {"type": "input_value", "name": "A"},
            {"type": "input_value", "name": "B"},
            {"type": "input_value", "name": "C"}
        ],
        "inputsInline": false,
        "output": null,
        "colour": 230,
        "tooltip": "Prüft ob MINDESTENS EINE der 3 Bedingungen wahr ist (SPS-Style)."
    },

    // --- 4-FACH ODER ---
    {
        "type": "ard_logic_or_4",
        "message0": "ODER (4-fach) %1 %2 %3 %4",
        "args0": [
            {"type": "input_value", "name": "A"},
            {"type": "input_value", "name": "B"},
            {"type": "input_value", "name": "C"},
            {"type": "input_value", "name": "D"}
        ],
        "inputsInline": false,
        "output": null,
        "colour": 230,
        "tooltip": "Prüft ob MINDESTENS EINE der 4 Bedingungen wahr ist (SPS-Style)."
    }
]);

// =======================================================================
// C++ CODE GENERATOREN
// =======================================================================

ArduinoGenerator.forBlock['ard_logic_and_3'] = function(block) {
    let a = ArduinoGenerator.valueToCode(block, 'A', 0) || 'false';
    let b = ArduinoGenerator.valueToCode(block, 'B', 0) || 'false';
    let c = ArduinoGenerator.valueToCode(block, 'C', 0) || 'false';
    // Sauber geklammert für C++
    return [`(${a} && ${b} && ${c})`, 0];
};

ArduinoGenerator.forBlock['ard_logic_and_4'] = function(block) {
    let a = ArduinoGenerator.valueToCode(block, 'A', 0) || 'false';
    let b = ArduinoGenerator.valueToCode(block, 'B', 0) || 'false';
    let c = ArduinoGenerator.valueToCode(block, 'C', 0) || 'false';
    let d = ArduinoGenerator.valueToCode(block, 'D', 0) || 'false';
    return [`(${a} && ${b} && ${c} && ${d})`, 0];
};

ArduinoGenerator.forBlock['ard_logic_or_3'] = function(block) {
    let a = ArduinoGenerator.valueToCode(block, 'A', 0) || 'false';
    let b = ArduinoGenerator.valueToCode(block, 'B', 0) || 'false';
    let c = ArduinoGenerator.valueToCode(block, 'C', 0) || 'false';
    return [`(${a} || ${b} || ${c})`, 0];
};

ArduinoGenerator.forBlock['ard_logic_or_4'] = function(block) {
    let a = ArduinoGenerator.valueToCode(block, 'A', 0) || 'false';
    let b = ArduinoGenerator.valueToCode(block, 'B', 0) || 'false';
    let c = ArduinoGenerator.valueToCode(block, 'C', 0) || 'false';
    let d = ArduinoGenerator.valueToCode(block, 'D', 0) || 'false';
    return [`(${a} || ${b} || ${c} || ${d})`, 0];
};