<?php
require_once dirname(__DIR__) . '/config/config.php';
require_once dirname(__DIR__) . '/includes/db.php';
require_once dirname(__DIR__) . '/includes/functions.php';
require_once dirname(__DIR__) . '/includes/api.php';
require_once dirname(__DIR__) . '/includes/functions_notes.php';

try {
    $songId = (int)($_GET['song_id'] ?? 0);
    if ($songId <= 0) {
        apiError('유효하지 않은 곡 ID입니다.', 'INVALID_REQUEST', 400);
    }

    $note = ensureUtf8String(getSongNote($songId)['note_text'] ?? '');
    $rating = getSongRating($songId);

    apiSuccess(
        ['note' => $note, 'rating' => $rating],
        '',
        [],
        ['note' => $note, 'rating' => $rating]
    );
} catch (Throwable $e) {
    apiHandleThrowable($e, 'SERVER_ERROR', 500, [
        'song_id' => $_GET['song_id'] ?? null,
    ]);
}
