-- Add vip_orders table for real VIP upgrade flow.
-- The app also creates this table defensively in app.php via CREATE TABLE IF NOT EXISTS.

CREATE TABLE IF NOT EXISTS vip_orders (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id INT UNSIGNED NOT NULL,
    from_level TINYINT UNSIGNED NOT NULL DEFAULT 0,
    to_level TINYINT UNSIGNED NOT NULL,
    price_usdt DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    status VARCHAR(32) NOT NULL DEFAULT 'completed',
    available_after DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    note VARCHAR(255) NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    completed_at DATETIME NULL,
    CONSTRAINT fk_vip_order_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
    INDEX idx_vip_orders_user_created (user_id, created_at),
    INDEX idx_vip_orders_status_created (status, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
