-- ============================================================================
-- Table structure for llx_tm_operator_skill
-- Actual competence level of an operator for a skill within a specific area.
--
-- level_type:
--   'numeric' — level 0-4 (see scale below)
--   'ea'      — External/Customer Approval (ea_ref + ea_expiry required)
--   'na'      — Not yet assessed (temporary)
--
-- Level scale:
--   0 = Training towards level 1
--   1 = Can operate without supervision (cannot train)
--   2 = Can operate + train operators to Level 1
--   3 = Can operate + train to Level 1 & 2 (Setting Laser/Form)
--   4 = Working Cell Leader — can train to levels 1, 2 & 3
-- ============================================================================

CREATE TABLE IF NOT EXISTS llx_tm_operator_skill (
    rowid         INTEGER      NOT NULL AUTO_INCREMENT PRIMARY KEY,
    fk_user       INTEGER      NOT NULL,
    fk_area       INTEGER      NOT NULL,
    fk_skill      INTEGER      NOT NULL,
    level         TINYINT      NOT NULL DEFAULT 0,
    level_type    ENUM('numeric','ea','na') NOT NULL DEFAULT 'numeric',
    ea_ref        VARCHAR(128) DEFAULT NULL,
    ea_expiry     DATE         DEFAULT NULL,
    note          TEXT         DEFAULT NULL,
    date_eval     DATE         DEFAULT NULL,
    tms           TIMESTAMP    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    fk_user_creat INTEGER      DEFAULT NULL,
    fk_user_modif INTEGER      DEFAULT NULL,
    import_key    VARCHAR(14)  DEFAULT NULL,
    UNIQUE KEY uk_tm_op_area_skill (fk_user, fk_area, fk_skill)
) ENGINE=innodb DEFAULT CHARSET=utf8mb4;
