import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEpisode"; import { buildNewEpisodeTaskId } from "~/libs/tasks/id"; import { removeTask } from "~/libs/tasks/removeTask"; import { setWatchStatus } from "~/models/watchStatus"; import { WatchStatus } from "~/types/title/watchStatus"; export async function updateWatchStatus( deviceId: string, titleId: number, watchStatus: WatchStatus | null, ) { const { wasAdded, wasDeleted } = await setWatchStatus( deviceId, Number(titleId), watchStatus, ); if (wasAdded) { await maybeScheduleNextAiringEpisode(titleId); } else if (wasDeleted) { await removeTask("NEW_EPISODE", buildNewEpisodeTaskId(titleId)); } }