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

// Database connection
$servername = "sql.freedb.tech";
$username = "freedb_dexterso_adhd_ln";
$password = "M-L8ehOLaFOm";
$dbname = "freedb_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;
}

// Query to join video_transcriptions and tbl_videos tables
$sql = "SELECT vt.video_id, vt.summary, vt.transcript, v.lesson_name, v.subject 
        FROM video_transcriptions vt 
        INNER JOIN tbl_videos v ON vt.video_id = v.video_id";

$result = $conn->query($sql);

if ($result) {
    $notes = [];
    while ($row = $result->fetch_assoc()) {
        $notes[] = [
            'video_id' => $row['video_id'],
            'lesson_name' => $row['lesson_name'],
            'subject' => $row['subject'],
            'summary' => $row['summary'],
            'transcript' => $row['transcript']
        ];
    }
    
    echo json_encode([
        'status' => 'success',
        'data' => $notes
    ]);
} else {
    echo json_encode([
        'status' => 'error',
        'message' => 'Failed to fetch notes: ' . $conn->error
    ]);
}

$conn->close();
?> 