-- ============================================================================
-- Copyright (C) 2026 Alles Watt lauft
--
-- Medium Types (Kabeltypen, Leitungsarten) for connections
-- System-specific: NYM/NYY for electrical, CAT5/CAT6/LWL for network, etc.
-- ============================================================================

CREATE TABLE IF NOT EXISTS llx_kundenkarte_medium_type
(
    rowid               integer AUTO_INCREMENT PRIMARY KEY,
    entity              integer DEFAULT 0 NOT NULL,

    ref                 varchar(50) NOT NULL,
    label               varchar(128) NOT NULL,
    label_short         varchar(32),
    description         text,

    -- System assignment (0 = all systems)
    fk_system           integer DEFAULT 0,

    -- Category for grouping
    category            varchar(50),          -- 'stromkabel', 'netzwerkkabel', 'lwl', 'koax', etc.

    -- Default specifications
    default_spec        varchar(100),         -- e.g., "3x1,5" for NYM
    available_specs     text,                 -- JSON array: ["3x1,5", "3x2,5", "5x1,5", "5x2,5", "5x4"]

    -- Display
    color               varchar(20),          -- Default wire color for display
    picto               varchar(128),

    -- Linked product (optional)
    fk_product          integer,

    is_system           tinyint DEFAULT 0,    -- System-defined (not deletable)
    position            integer DEFAULT 0,
    active              tinyint DEFAULT 1,

    date_creation       datetime,
    tms                 timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    fk_user_creat       integer,
    fk_user_modif       integer,

    UNIQUE KEY uk_medium_type_ref (ref, entity),
    INDEX idx_medium_system (fk_system),
    INDEX idx_medium_category (category)
) ENGINE=innodb;
