-- ============================================================================
-- Copyright (C) 2026 Alles Watt lauft
--
-- Table for equipment type templates (Hutschienen-Komponenten)
-- Examples: Leitungsschutzschalter, FI-Schalter, Hauptschalter, etc.
-- ============================================================================

CREATE TABLE llx_kundenkarte_equipment_type
(
    rowid               integer AUTO_INCREMENT PRIMARY KEY,
    entity              integer DEFAULT 0 NOT NULL,

    ref                 varchar(64) NOT NULL,
    label               varchar(255) NOT NULL,
    label_short         varchar(32),
    description         text,

    fk_system           integer NOT NULL,

    -- Equipment-spezifische Felder
    width_te            integer DEFAULT 1 NOT NULL COMMENT 'Standardbreite in Teilungseinheiten (TE)',
    color               varchar(8) COMMENT 'Farbcode fuer SVG-Darstellung (z.B. #3498db)',

    -- Optionale Produkt-Verknuepfung
    fk_product          integer DEFAULT NULL COMMENT 'Optionales Standard-Dolibarr-Produkt',

    -- Terminal-Konfiguration (JSON)
    terminals_config    text COMMENT 'JSON config for terminals',

    -- Stromrichtung und Terminal-Position
    flow_direction      varchar(16) DEFAULT NULL COMMENT 'Stromrichtung: NULL=keine, top_to_bottom, bottom_to_top',
    terminal_position   varchar(16) DEFAULT 'both' COMMENT 'Terminal-Position: both, top_only, bottom_only',

    picto               varchar(64),
    icon_file           varchar(255) COMMENT 'Uploaded SVG/PNG file for schematic symbol (PDF)',
    block_image         varchar(255) COMMENT 'Uploaded image for block display in SchematicEditor',
    is_system           tinyint DEFAULT 0 NOT NULL,

    position            integer DEFAULT 0,
    active              tinyint DEFAULT 1 NOT NULL,

    date_creation       datetime,
    tms                 timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    fk_user_creat       integer,
    fk_user_modif       integer,
    import_key          varchar(14)
) ENGINE=innodb;
