CREATE TABLE IF NOT EXISTS `templates` (
    `id`          BIGINT UNSIGNED  NOT NULL AUTO_INCREMENT,
    `name`        VARCHAR(255)     NOT NULL,
    `description` TEXT             NULL DEFAULT NULL,
    `industry`    VARCHAR(64)      NOT NULL
                      COMMENT 'hotel|shipping|church|visa|restaurant|store|education|agency',
    `style`       VARCHAR(64)      NOT NULL
                      COMMENT 'apple|luxury|dark|modern|corporate',
    `thumbnail`   VARCHAR(512)     NULL DEFAULT NULL
                      COMMENT 'Relative path: storage/uploads/templates/{id}/thumbnail.{ext}',
    `json_data`   JSON             NOT NULL
                      COMMENT 'Full template configuration object',
    `tags`        JSON             NULL DEFAULT NULL
                      COMMENT 'Array of string tags for search',
    `preview_url` VARCHAR(512)     NULL DEFAULT NULL
                      COMMENT 'Optional live preview URL',
    `is_active`   TINYINT(1)       NOT NULL DEFAULT 1,
    `sort_order`  SMALLINT         NOT NULL DEFAULT 0,
    `created_at`  DATETIME         NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`  DATETIME         NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    INDEX `idx_templates_industry` (`industry`),
    INDEX `idx_templates_style`    (`style`),
    INDEX `idx_templates_active`   (`is_active`),
    INDEX `idx_templates_sort`     (`sort_order`),
    FULLTEXT INDEX `ft_templates_search` (`name`, `description`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
