import { apiFetch } from "./auth"; export type ScheduleTaskType = | "START" | "STOP" | "RESTART" | "BACKUP" | "CONSOLE_COMMAND" | "UPDATE_CHECK" | "MAINTENANCE"; export interface ScheduledTask { id: string; taskType: ScheduleTaskType; payload: Record | null; } export interface Schedule { id: string; name: string; timezone: string; cronExpr: string; enabled: boolean; nextRunAt: string | null; lastRunAt: string | null; tasks: ScheduledTask[]; } export interface ScheduleListResponse { schedules: Schedule[]; } export interface CreateSchedulePayload { name: string; timezone?: string; cronExpr: string; enabled?: boolean; tasks: Array<{ taskType: ScheduleTaskType; payload?: Record; }>; } export type UpdateSchedulePayload = Partial; export async function listSchedules(serverId: string): Promise { return apiFetch(`/servers/${serverId}/schedules`); } export async function createSchedule( serverId: string, payload: CreateSchedulePayload, ): Promise { return apiFetch(`/servers/${serverId}/schedules`, { method: "POST", body: JSON.stringify(payload), }); } export async function updateSchedule( serverId: string, scheduleId: string, payload: UpdateSchedulePayload, ): Promise { return apiFetch(`/servers/${serverId}/schedules/${scheduleId}`, { method: "PATCH", body: JSON.stringify(payload), }); } export async function deleteSchedule( serverId: string, scheduleId: string, ): Promise { await apiFetch(`/servers/${serverId}/schedules/${scheduleId}`, { method: "DELETE", }); }