-- =====================================================
-- ACTUALIZACIÓN v2.1.1 - Sistema de Monedas Mejorado
-- =====================================================

-- 1. Agregar columna para emojis de banderas (si no existe)
ALTER TABLE tp_currencies 
ADD COLUMN IF NOT EXISTS flag_emoji VARCHAR(10) NULL AFTER symbol;

-- 2. Actualizar banderas de países hispanohablantes
UPDATE tp_currencies SET flag_emoji = '🇺🇸' WHERE code = 'USD';
UPDATE tp_currencies SET flag_emoji = '🇲🇽' WHERE code = 'MXN';
UPDATE tp_currencies SET flag_emoji = '🇨🇴' WHERE code = 'COP';
UPDATE tp_currencies SET flag_emoji = '🇦🇷' WHERE code = 'ARS';
UPDATE tp_currencies SET flag_emoji = '🇧🇷' WHERE code = 'BRL';
UPDATE tp_currencies SET flag_emoji = '🇨🇱' WHERE code = 'CLP';
UPDATE tp_currencies SET flag_emoji = '🇵🇪' WHERE code = 'PEN';
UPDATE tp_currencies SET flag_emoji = '🇩🇴' WHERE code = 'DOP';
UPDATE tp_currencies SET flag_emoji = '🇺🇾' WHERE code = 'UYU';
UPDATE tp_currencies SET flag_emoji = '🇵🇾' WHERE code = 'PYG';
UPDATE tp_currencies SET flag_emoji = '🇧🇴' WHERE code = 'BOB';
UPDATE tp_currencies SET flag_emoji = '🇻🇪' WHERE code = 'VES';
UPDATE tp_currencies SET flag_emoji = '🇨🇺' WHERE code = 'CUP';
UPDATE tp_currencies SET flag_emoji = '🇨🇷' WHERE code = 'CRC';
UPDATE tp_currencies SET flag_emoji = '🇬🇹' WHERE code = 'GTQ';
UPDATE tp_currencies SET flag_emoji = '🇭🇳' WHERE code = 'HNL';
UPDATE tp_currencies SET flag_emoji = '🇳🇮' WHERE code = 'NIO';
UPDATE tp_currencies SET flag_emoji = '🇵🇦' WHERE code = 'PAB';
UPDATE tp_currencies SET flag_emoji = '🇸🇻' WHERE code = 'SVC';
UPDATE tp_currencies SET flag_emoji = '🇪🇸' WHERE code = 'EUR';
UPDATE tp_currencies SET flag_emoji = '🇬🇧' WHERE code = 'GBP';
UPDATE tp_currencies SET flag_emoji = '🇨🇭' WHERE code = 'CHF';
UPDATE tp_currencies SET flag_emoji = '🇬🇶' WHERE code = 'XAF';
UPDATE tp_currencies SET flag_emoji = '🪙' WHERE code = 'USDT';
UPDATE tp_currencies SET flag_emoji = '🪙' WHERE code = 'USDC';
UPDATE tp_currencies SET flag_emoji = '🪙' WHERE code = 'BTC';
UPDATE tp_currencies SET flag_emoji = '🪙' WHERE code = 'ETH';

-- 3. Crear tabla tp_renewal_requests si no existe
CREATE TABLE IF NOT EXISTS tp_renewal_requests (
  id int(11) NOT NULL AUTO_INCREMENT,
  store_id int(11) NOT NULL,
  customer_id int(11) NOT NULL,
  order_item_id int(11) NOT NULL,
  duration_months int(11) NOT NULL,
  price decimal(10,2) NOT NULL,
  payment_method varchar(50) DEFAULT NULL,
  status enum('pending','approved','rejected','expired') DEFAULT 'pending',
  admin_notes text,
  created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  processed_at timestamp NULL DEFAULT NULL,
  processed_by int(11) DEFAULT NULL,
  PRIMARY KEY (id),
  KEY store_id (store_id),
  KEY customer_id (customer_id),
  KEY order_item_id (order_item_id),
  KEY status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- =====================================================
-- FIN DE ACTUALIZACIÓN
-- =====================================================
