//
// Jellyfin favourite item API. Optimistic local update + fire-and-forget HTTP.
//

jellyfin_toggle_favourite :: (track_id: string, currently_favourite: bool) {
    path   := tprint("/Users/%/FavoriteItems/%", app.jellyfin.user_id, track_id);
    method := ifx currently_favourite then "DELETE" else "POST";
    log_info("fav: % %", method, path);
    http_submit(method, path, on_done=on_fav_response);
}

#scope_file

on_fav_response :: (task: *Http_Task) {
    if task.response.ok {
        log_info("fav: server accepted (status=%)", task.response.status_code);
    } else {
        log_warn("fav: server rejected (status=%) body=%",
            task.response.status_code,
            slice(task.response.body, 0, min(200, task.response.body.count)));
    }
}
