/*
 TechStackBase – Modules
 Version: v1.0.0
 Purpose: Define system modules for UI, permissions, and subscriptions

 DESIGN PRINCIPLES
 -----------------
 • Declarative (data-driven modules)
 • UI + backend aligned
 • Subscription-aware
 • Permission-aware
 • No business logic in code
*/

/* ============================================================
   MODULES TABLE
   ============================================================ */

CREATE TABLE modules (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,

    /* Stable identifier (used everywhere) */
    code VARCHAR(64) NOT NULL,

    /* Display */
    name VARCHAR(128) NOT NULL,
    description TEXT NULL,
    icon VARCHAR(64) NULL,

    /* Ordering */
    sort_order INT NOT NULL DEFAULT 0,

    /* Status */
    active TINYINT(1) NOT NULL DEFAULT 1,

    /* Metadata */
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,

    /* Constraints */
    UNIQUE KEY uq_modules_code (code),
    INDEX idx_modules_active (active),
    INDEX idx_modules_sort (sort_order)
) ENGINE=InnoDB
  ROW_FORMAT=DYNAMIC
  COMMENT='System modules (authoritative)';
