-- Migration 036: Correct default policy for UI contract tabs (enforce hide)
-- and ensure all new tabs (SSH, HTTP, Network Probe, QR, FTP) have correct policy.
-- Uses INSERT ... ON DUPLICATE KEY UPDATE to guarantee correct state regardless of dashboard edits.

-- UI Contract Tabs: must be hidden by default (developer-only, never show to end users by default)
INSERT 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())
ON DUPLICATE KEY UPDATE visibility = 'hide', min_tier = 'developer', updated_at = NOW();

INSERT 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())
ON DUPLICATE KEY UPDATE visibility = 'hide', min_tier = 'developer', updated_at = NOW();

-- New tech tabs: ensure policy exists with 'show' if not already set
INSERT IGNORE INTO app_feature_policy (tab_id, visibility, message_type, message_content, min_tier, allow_override_for_developer_admin, updated_at) VALUES
  ('sshTab',           'show', 'none', NULL, 'trial', 1, NOW()),
  ('httpClientTab',    'show', 'none', NULL, 'trial', 1, NOW()),
  ('networkProbeTab',  'show', 'none', NULL, 'trial', 1, NOW()),
  ('qrGeneratorTab',   'show', 'none', NULL, 'trial', 1, NOW()),
  ('ftpTab',           '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
  ('sshTab',           'show', 'none', NULL, 'trial', 1, NOW()),
  ('httpClientTab',    'show', 'none', NULL, 'trial', 1, NOW()),
  ('networkProbeTab',  'show', 'none', NULL, 'trial', 1, NOW()),
  ('qrGeneratorTab',   'show', 'none', NULL, 'trial', 1, NOW()),
  ('ftpTab',           'show', 'none', NULL, 'trial', 1, NOW());
