<?php
require_once 'config.php';
require_once 'includes/db.php';

echo "Setting up a test video and user...\n";

try {
    // 1. Ensure at least one user exists (ID 1)
    $stmt = $pdo->query("SELECT id FROM users LIMIT 1");
    $user_id = $stmt->fetchColumn();
    
    if (!$user_id) {
        $stmt = $pdo->prepare("INSERT INTO users (name, email, password, role, api_key) VALUES ('Test User', 'test@test.com', 'password', 'user', 'pk_live_09452dd114a500e6cc553d7c4bcd3758')");
        $stmt->execute();
        $user_id = $pdo->lastInsertId();
    } else {
        // Update user 1 to have the live API key for testing
        $stmt = $pdo->prepare("UPDATE users SET api_key = 'pk_live_09452dd114a500e6cc553d7c4bcd3758' WHERE id = ?");
        $stmt->execute([$user_id]);
    }

    // 2. Create a dummy video
    $video_id = 'test-vid-' . time();
    $stmt = $pdo->prepare("INSERT INTO videos (id, user_id, title, description, price, status) VALUES (?, ?, 'Test Premium Video', 'A special test for Kindamba Pay', 500.00, 'active')");
    $stmt->execute([$video_id, $user_id]);

    echo "Success! Video ID: $video_id\n";
    echo "User ID: $user_id\n";
    
} catch (PDOException $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>
