-- =============================================================================
-- Migration 092: Tool Configure Permissions + Nextcloud Feature Group
-- =============================================================================

-- Feature group: nextcloud
INSERT INTO feature_groups (id, label, sort_order)
VALUES ('nextcloud', 'Nextcloud', 11)
ON CONFLICT (id) DO NOTHING;

-- Configure permissions for wissen, vikunja, nextcloud
INSERT INTO permissions (id, feature_group_id, label, description, sort_order) VALUES
  ('wissen:configure',    'wissen',    'Konfigurieren', 'BookStack-Verbindung konfigurieren',    10),
  ('vikunja:configure',   'vikunja',   'Konfigurieren', 'Vikunja-Verbindung konfigurieren',      10),
  ('nextcloud:configure', 'nextcloud', 'Konfigurieren', 'Nextcloud-Verbindung konfigurieren',    1)
ON CONFLICT (id) DO NOTHING;

-- Grant all 3 configure permissions to dashboard_kommando
INSERT INTO group_permissions (authentik_group, permission_id) VALUES
  ('dashboard_kommando', 'wissen:configure'),
  ('dashboard_kommando', 'vikunja:configure'),
  ('dashboard_kommando', 'nextcloud:configure')
ON CONFLICT DO NOTHING;

-- Seed default app_settings for tool configs
INSERT INTO app_settings (key, value) VALUES
  ('tool_config_bookstack', '{}'::jsonb),
  ('tool_config_vikunja',   '{}'::jsonb),
  ('tool_config_nextcloud', '{}'::jsonb)
ON CONFLICT (key) DO NOTHING;
