<?php
header('Content-Type: application/json');

// Database connection
$servername = "localhost";
$username = "dexterso_adhd_lnapp_user";
$password = "M-L8ehOLaFOm";
$dbname = "dexterso_adhd_app";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    echo json_encode([
        'status' => 'error',
        'message' => 'Database connection failed'
    ]);
    exit;
}

// Get video_id from request
$video_id = isset($_GET['video_id']) ? intval($_GET['video_id']) : 0;

if ($video_id <= 0) {
    echo json_encode([
        'status' => 'error',
        'message' => 'Invalid video ID'
    ]);
    exit;
}

// Query to get transcript for the specific video_id
$sql = "SELECT transcript FROM video_transcriptions WHERE video_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $video_id);
$stmt->execute();
$result = $stmt->get_result();

if ($result && $row = $result->fetch_assoc()) {
    echo json_encode([
        'status' => 'success',
        'transcript' => $row['transcript']
    ]);
} else {
    echo json_encode([
        'status' => 'error',
        'message' => 'Transcript not found for this video'
    ]);
}

$stmt->close();
$conn->close();
?> 