-- Add indexes for admin panel queries to improve performance
-- This migration adds indexes for filtering, searching, and dashboard statistics

-- ============================================
-- db_users_a indexes
-- ============================================
-- Index for registration date filtering and counting (dashboard stats)
CREATE INDEX idx_users_date_reg ON db_users_a(date_reg);

-- Index for login date filtering and counting active users (dashboard stats)
CREATE INDEX idx_users_date_login ON db_users_a(date_login);

-- Index for banned status filtering
CREATE INDEX idx_users_banned ON db_users_a(banned);

-- Index for country code filtering
CREATE INDEX idx_users_country_code ON db_users_a(country_code);

-- Index for language code filtering
CREATE INDEX idx_users_language_code ON db_users_a(language_code);

-- ============================================
-- payments indexes
-- ============================================
-- Composite index for dashboard queries: sumTicketsAmountByStatusAndCreatedAtAfter
-- This optimizes queries that filter by status and created_at (e.g., revenue stats)
CREATE INDEX idx_payments_status_created_at ON payments(status, created_at);

-- ============================================
-- payouts indexes
-- ============================================
-- Composite index for dashboard queries: sumTotalByStatusAndCreatedAtAfter
-- This optimizes queries that filter by status and created_at (e.g., payout stats)
CREATE INDEX idx_payouts_status_created_at ON payouts(status, created_at);

-- Index for payout type filtering
CREATE INDEX idx_payouts_type ON payouts(type);

-- ============================================
-- support_tickets indexes
-- ============================================
-- Index for updated_at filtering (dashboard: tickets resolved today)
CREATE INDEX idx_support_tickets_updated_at ON support_tickets(updated_at);

-- Composite index for common query pattern: status + updated_at
-- This helps with queries like countByStatusAndUpdatedAtAfter
CREATE INDEX idx_support_tickets_status_updated_at ON support_tickets(status, updated_at);

