-- ============================================================================
-- Copyright (C) 2026 Alles Watt lauft
--
-- Standard terminal block types (Reihenklemmen-Typen)
-- These are narrow components (0.5 TE) with stacked terminals
-- ============================================================================

-- Note: Run this after the module is installed and you have created a system
-- with code 'STROM' for electrical installations.
-- Adjust fk_system values to match your actual system IDs.

-- Get the electrical system ID (adjust WHERE clause if needed)
-- SET @strom_system = (SELECT rowid FROM llx_c_kundenkarte_anlage_system WHERE code = 'STROM' LIMIT 1);

-- ============================================================================
-- Reihenklemmen / Terminal Blocks (0.5 TE breit)
-- ============================================================================

-- Durchgangsklemme (Feed-through terminal) - 1 input, 1 output
-- Standard 2-point terminal block
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_DURCH', 'Durchgangsklemme', 'DK', 'Standard-Durchgangsklemme für Leiterverbindung',
    s.rowid, 1, '#7f8c8d',
    '{"terminals":[{"id":"t1","label":"1","pos":"top","col":0,"row":0},{"id":"t2","label":"2","pos":"bottom","col":0,"row":0}]}',
    'top_to_bottom', 'both', 'fa-square', 0, 100, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- Dreistockklemme (3-level terminal) - 3 top, 2 bottom
-- Used for phase distribution with multiple connection points
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_3STOCK', 'Dreistockklemme', '3ST', 'Dreistöckige Klemme für mehrfache Verbindungen',
    s.rowid, 1, '#27ae60',
    '{"terminals":[{"id":"t1","label":"1","pos":"top","col":0,"row":0},{"id":"t3","label":"3","pos":"top","col":0,"row":1},{"id":"t5","label":"5","pos":"top","col":0,"row":2},{"id":"t2","label":"2","pos":"bottom","col":0,"row":0},{"id":"t4","label":"4","pos":"bottom","col":0,"row":1}]}',
    NULL, 'both', 'fa-th-large', 0, 110, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- Doppelstockklemme (2-level terminal) - 2 top, 2 bottom
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_2STOCK', 'Doppelstockklemme', '2ST', 'Zweistöckige Klemme für doppelte Verbindungen',
    s.rowid, 1, '#2980b9',
    '{"terminals":[{"id":"t1","label":"1","pos":"top","col":0,"row":0},{"id":"t3","label":"3","pos":"top","col":0,"row":1},{"id":"t2","label":"2","pos":"bottom","col":0,"row":0},{"id":"t4","label":"4","pos":"bottom","col":0,"row":1}]}',
    NULL, 'both', 'fa-th', 0, 105, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- N-Klemme (Neutral terminal) - blaue Farbe
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_N', 'N-Klemme', 'N', 'Neutralleiter-Klemme (blau)',
    s.rowid, 1, '#3498db',
    '{"terminals":[{"id":"t1","label":"N","pos":"top","col":0,"row":0},{"id":"t2","label":"N","pos":"bottom","col":0,"row":0}]}',
    'top_to_bottom', 'both', 'fa-square', 0, 120, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- PE-Klemme (Protective Earth terminal) - grün-gelb
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_PE', 'PE-Klemme', 'PE', 'Schutzleiter-Klemme (grün-gelb)',
    s.rowid, 1, '#27ae60',
    '{"terminals":[{"id":"t1","label":"PE","pos":"top","col":0,"row":0},{"id":"t2","label":"PE","pos":"bottom","col":0,"row":0}]}',
    'top_to_bottom', 'both', 'fa-square', 0, 125, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- Hauptabzweigklemme (Main junction terminal) - 4 Anschlusspunkte
-- Large terminal for main distribution with 2 inputs and 2 outputs
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_HAK', 'Hauptabzweigklemme', 'HAK', 'Hauptabzweigklemme für große Querschnitte mit 4 Anschlüssen',
    s.rowid, 2, '#e74c3c',
    '{"terminals":[{"id":"t1","label":"1","pos":"top","col":0,"row":0},{"id":"t3","label":"3","pos":"top","col":1,"row":0},{"id":"t2","label":"2","pos":"bottom","col":0,"row":0},{"id":"t4","label":"4","pos":"bottom","col":1,"row":0}]}',
    NULL, 'both', 'fa-th-large', 0, 130, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- Trennklemme (Disconnect terminal) - mit Trennmöglichkeit
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_TRENN', 'Trennklemme', 'TK', 'Reihenklemme mit Trennmöglichkeit',
    s.rowid, 1, '#f39c12',
    '{"terminals":[{"id":"t1","label":"1","pos":"top","col":0,"row":0},{"id":"t2","label":"2","pos":"bottom","col":0,"row":0}]}',
    'top_to_bottom', 'both', 'fa-minus-square', 0, 115, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- Sicherungsklemme (Fuse terminal)
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_SI', 'Sicherungsklemme', 'SI', 'Reihenklemme mit Sicherungseinsatz',
    s.rowid, 1, '#c0392b',
    '{"terminals":[{"id":"t1","label":"1","pos":"top","col":0,"row":0},{"id":"t2","label":"2","pos":"bottom","col":0,"row":0}]}',
    'top_to_bottom', 'both', 'fa-bolt', 0, 135, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- LED-Klemme (Terminal with LED indicator)
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_LED', 'LED-Klemme', 'LED', 'Reihenklemme mit LED-Anzeige',
    s.rowid, 1, '#8e44ad',
    '{"terminals":[{"id":"t1","label":"1","pos":"top","col":0,"row":0},{"id":"t2","label":"2","pos":"bottom","col":0,"row":0}]}',
    'top_to_bottom', 'both', 'fa-lightbulb-o', 0, 140, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;

-- Vierfachklemme (4-level terminal) - für dichte Verdrahtung
INSERT INTO llx_kundenkarte_equipment_type
(entity, ref, label, label_short, description, fk_system, width_te, color, terminals_config, flow_direction, terminal_position, picto, is_system, position, active, date_creation)
SELECT 0, 'RK_4STOCK', 'Vierfachklemme', '4ST', 'Vierstöckige Klemme für sehr dichte Verdrahtung',
    s.rowid, 1, '#1abc9c',
    '{"terminals":[{"id":"t1","label":"1","pos":"top","col":0,"row":0},{"id":"t3","label":"3","pos":"top","col":0,"row":1},{"id":"t5","label":"5","pos":"top","col":0,"row":2},{"id":"t7","label":"7","pos":"top","col":0,"row":3},{"id":"t2","label":"2","pos":"bottom","col":0,"row":0},{"id":"t4","label":"4","pos":"bottom","col":0,"row":1},{"id":"t6","label":"6","pos":"bottom","col":0,"row":2}]}',
    NULL, 'both', 'fa-th', 0, 112, 1, NOW()
FROM llx_c_kundenkarte_anlage_system s WHERE s.code = 'STROM' LIMIT 1;
