-- Migration 009 Down: Remove Secure Messenger System

-- Drop triggers
DROP TRIGGER IF EXISTS messenger_relay_nodes_updated ON messenger_relay_nodes;
DROP TRIGGER IF EXISTS messenger_conversations_updated ON messenger_conversations;
DROP TRIGGER IF EXISTS messenger_contact_groups_updated ON messenger_contact_groups;
DROP TRIGGER IF EXISTS messenger_contacts_updated ON messenger_contacts;
DROP TRIGGER IF EXISTS messenger_profiles_updated ON messenger_profiles;

DROP FUNCTION IF EXISTS update_messenger_timestamp();

-- Drop indexes
DROP INDEX IF EXISTS idx_messenger_relay_active;
DROP INDEX IF EXISTS idx_messenger_peer_registry_trusted;
DROP INDEX IF EXISTS idx_messenger_peer_registry_type;
DROP INDEX IF EXISTS idx_messenger_messages_ipfs;
DROP INDEX IF EXISTS idx_messenger_messages_created;
DROP INDEX IF EXISTS idx_messenger_messages_sender;
DROP INDEX IF EXISTS idx_messenger_messages_conversation;
DROP INDEX IF EXISTS idx_messenger_members_user;
DROP INDEX IF EXISTS idx_messenger_members_conversation;
DROP INDEX IF EXISTS idx_messenger_conversations_owner;
DROP INDEX IF EXISTS idx_messenger_conversations_type;
DROP INDEX IF EXISTS idx_messenger_blocklist_peer;
DROP INDEX IF EXISTS idx_messenger_blocklist_blocked;
DROP INDEX IF EXISTS idx_messenger_blocklist_owner;
DROP INDEX IF EXISTS idx_messenger_contacts_messaging_id;
DROP INDEX IF EXISTS idx_messenger_contacts_status;
DROP INDEX IF EXISTS idx_messenger_contacts_owner;
DROP INDEX IF EXISTS idx_messenger_keys_type;
DROP INDEX IF EXISTS idx_messenger_keys_user_active;
DROP INDEX IF EXISTS idx_messenger_profiles_status;
DROP INDEX IF EXISTS idx_messenger_profiles_peer_id;
DROP INDEX IF EXISTS idx_messenger_profiles_messaging_id;

-- Drop tables in reverse dependency order
DROP TABLE IF EXISTS messenger_relay_nodes;
DROP TABLE IF EXISTS messenger_peer_registry;
DROP TABLE IF EXISTS messenger_read_receipts;
DROP TABLE IF EXISTS messenger_messages;
DROP TABLE IF EXISTS messenger_conversation_members;
DROP TABLE IF EXISTS messenger_conversations;
DROP TABLE IF EXISTS messenger_blocklist;
DROP TABLE IF EXISTS messenger_contact_groups;
DROP TABLE IF EXISTS messenger_contacts;
DROP TABLE IF EXISTS messenger_keys;
DROP TABLE IF EXISTS messenger_profiles;
