-- Migration 010 Down: Remove Enhanced Payment System

-- Drop triggers
DROP TRIGGER IF EXISTS donation_completed ON donations;
DROP TRIGGER IF EXISTS subscriptions_updated ON subscriptions;
DROP TRIGGER IF EXISTS donations_updated ON donations;
DROP TRIGGER IF EXISTS donation_campaigns_updated ON donation_campaigns;
DROP TRIGGER IF EXISTS payment_crypto_details_updated ON payment_crypto_details;
DROP TRIGGER IF EXISTS payment_gateways_updated ON payment_gateways;
DROP TRIGGER IF EXISTS payment_wallets_updated ON payment_wallets;
DROP TRIGGER IF EXISTS payment_tokens_updated ON payment_tokens;
DROP TRIGGER IF EXISTS payment_networks_updated ON payment_networks;

DROP FUNCTION IF EXISTS update_campaign_stats();

-- Drop indexes
DROP INDEX IF EXISTS idx_subscriptions_status;
DROP INDEX IF EXISTS idx_subscriptions_user;
DROP INDEX IF EXISTS idx_exchange_rates_history_pair;
DROP INDEX IF EXISTS idx_exchange_rates_pair;
DROP INDEX IF EXISTS idx_campaigns_public;
DROP INDEX IF EXISTS idx_campaigns_active;
DROP INDEX IF EXISTS idx_campaigns_slug;
DROP INDEX IF EXISTS idx_donations_recurring;
DROP INDEX IF EXISTS idx_donations_created;
DROP INDEX IF EXISTS idx_donations_status;
DROP INDEX IF EXISTS idx_donations_donor;
DROP INDEX IF EXISTS idx_donations_campaign;
DROP INDEX IF EXISTS idx_payment_audit_created;
DROP INDEX IF EXISTS idx_payment_audit_action;
DROP INDEX IF EXISTS idx_payment_audit_invoice;
DROP INDEX IF EXISTS idx_payment_audit_payment;
DROP INDEX IF EXISTS idx_payment_crypto_confirmed;
DROP INDEX IF EXISTS idx_payment_crypto_network;
DROP INDEX IF EXISTS idx_payment_crypto_tx;
DROP INDEX IF EXISTS idx_payment_crypto_payment;
DROP INDEX IF EXISTS idx_payment_gateways_enabled;
DROP INDEX IF EXISTS idx_payment_gateways_code;
DROP INDEX IF EXISTS idx_payment_wallets_primary;
DROP INDEX IF EXISTS idx_payment_wallets_active;
DROP INDEX IF EXISTS idx_payment_wallets_network;
DROP INDEX IF EXISTS idx_payment_tokens_contract;
DROP INDEX IF EXISTS idx_payment_tokens_enabled;
DROP INDEX IF EXISTS idx_payment_tokens_verified;
DROP INDEX IF EXISTS idx_payment_tokens_symbol;
DROP INDEX IF EXISTS idx_payment_tokens_network;
DROP INDEX IF EXISTS idx_payment_networks_enabled;
DROP INDEX IF EXISTS idx_payment_networks_code;

-- Drop tables in reverse dependency order
DROP TABLE IF EXISTS subscriptions;
DROP TABLE IF EXISTS subscription_plans;
DROP TABLE IF EXISTS exchange_rates_history;
DROP TABLE IF EXISTS exchange_rates;
DROP TABLE IF EXISTS donation_tiers;
DROP TABLE IF EXISTS donations;
DROP TABLE IF EXISTS donation_campaigns;
DROP TABLE IF EXISTS payment_audit_log;
DROP TABLE IF EXISTS payment_crypto_details;
DROP TABLE IF EXISTS payment_gateway_currencies;
DROP TABLE IF EXISTS payment_gateways;
DROP TABLE IF EXISTS payment_wallets;
DROP TABLE IF EXISTS payment_tokens;
DROP TABLE IF EXISTS payment_networks;

-- Note: We don't remove the added enum values as that would break existing data
-- The enum values (PAYPAL, CRYPTO_USDT, etc.) remain in payment_method type
