-- Migration 026: Seed missing app tabs and create missing tables.
-- Adds workerControlTab (was in 021/023 but not applied to DB),
-- uiContractShellTab, uiContractFormsTab, uiContractDataTab (new UI contract tabs),
-- and creates e2e_results table used by delete_all_e2e_results.php.

-- 1. Worker Control Tab (high sort_order used by app: 23, but place after existing max)
INSERT IGNORE INTO app_tabs (tab_id, label, icon, sort_order, content_type, content_slug, requires_token, created_at, updated_at) VALUES
('workerControlTab', 'Worker Control', '👷', 26, 'native', NULL, 0, NOW(), NOW());
INSERT IGNORE INTO ftt_app_tabs (tab_id, label, icon, sort_order, content_type, content_slug, requires_token, created_at, updated_at) VALUES
('workerControlTab', 'Worker Control', '👷', 26, 'native', NULL, 0, NOW(), NOW());
INSERT IGNORE INTO app_feature_policy (tab_id, visibility, message_type, message_content, min_tier, allow_override_for_developer_admin, updated_at) VALUES
('workerControlTab', 'show', 'none', NULL, 'trial', 1, NOW());
INSERT IGNORE INTO ftt_app_feature_policy (tab_id, visibility, message_type, message_content, min_tier, allow_override_for_developer_admin, updated_at) VALUES
('workerControlTab', 'show', 'none', NULL, 'trial', 1, NOW());

-- 2. UI Contract Tabs (internal developer/admin tools, sort_order 9500-9502 per app)
INSERT IGNORE INTO app_tabs (tab_id, label, icon, sort_order, content_type, content_slug, requires_token, created_at, updated_at) VALUES
('uiContractShellTab', 'UI: Shell', '📐', 9500, 'native', NULL, 0, NOW(), NOW()),
('uiContractFormsTab', 'UI: Forms', '📋', 9501, 'native', NULL, 0, NOW(), NOW()),
('uiContractDataTab',  'UI: Data',  '📊', 9502, 'native', NULL, 0, NOW(), NOW());
INSERT IGNORE INTO ftt_app_tabs (tab_id, label, icon, sort_order, content_type, content_slug, requires_token, created_at, updated_at) VALUES
('uiContractShellTab', 'UI: Shell', '📐', 9500, 'native', NULL, 0, NOW(), NOW()),
('uiContractFormsTab', 'UI: Forms', '📋', 9501, 'native', NULL, 0, NOW(), NOW()),
('uiContractDataTab',  'UI: Data',  '📊', 9502, 'native', NULL, 0, NOW(), NOW());
INSERT IGNORE INTO app_feature_policy (tab_id, visibility, message_type, message_content, min_tier, allow_override_for_developer_admin, updated_at) VALUES
('uiContractShellTab', 'hide', 'none', NULL, 'developer', 1, NOW()),
('uiContractFormsTab', 'hide', 'none', NULL, 'developer', 1, NOW()),
('uiContractDataTab',  'hide', 'none', NULL, 'developer', 1, NOW());
INSERT IGNORE INTO ftt_app_feature_policy (tab_id, visibility, message_type, message_content, min_tier, allow_override_for_developer_admin, updated_at) VALUES
('uiContractShellTab', 'hide', 'none', NULL, 'developer', 1, NOW()),
('uiContractFormsTab', 'hide', 'none', NULL, 'developer', 1, NOW()),
('uiContractDataTab',  'hide', 'none', NULL, 'developer', 1, NOW());

-- 3. E2E Results table (used by api/delete_all_e2e_results.php)
CREATE TABLE IF NOT EXISTS e2e_results (
    id INT AUTO_INCREMENT PRIMARY KEY,
    test_name VARCHAR(128) NOT NULL,
    status VARCHAR(16) NOT NULL,
    duration_ms INT DEFAULT 0,
    error_message TEXT,
    created_at DATETIME NOT NULL,
    INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS ftt_e2e_results (
    id INT AUTO_INCREMENT PRIMARY KEY,
    test_name VARCHAR(128) NOT NULL,
    status VARCHAR(16) NOT NULL,
    duration_ms INT DEFAULT 0,
    error_message TEXT,
    created_at DATETIME NOT NULL,
    INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
