/**
 * Autoplay API
 *
 * Functions to control autoplay in the backend.
 */

import { commands } from "$lib/api/bindings";
import type { PlayItemRequest, AutoplaySettings } from "$lib/api/bindings";
import { auth } from "$lib/stores/auth";

export type { AutoplaySettings };

export async function getAutoplaySettings(): Promise<AutoplaySettings> {
  return commands.playerGetAutoplaySettings();
}

export async function setAutoplaySettings(
  settings: AutoplaySettings
): Promise<AutoplaySettings> {
  return commands.playerSetAutoplaySettings(auth.getUserId() ?? "", settings);
}

export async function cancelAutoplayCountdown(): Promise<void> {
  await commands.playerCancelAutoplayCountdown();
}

export async function playNextEpisode(item: PlayItemRequest): Promise<void> {
  await commands.playerPlayNextEpisode(item);
}
