import { get, post } from "./shared";
import type {
	SchedulerManualRunResponse,
	SchedulerRunsResponse,
	SchedulerSamplesResponse,
	SchedulerStatus,
} from "../types";

export function fetchSchedulerStatus(
	serviceId: string,
): Promise<SchedulerStatus> {
	return get<SchedulerStatus>(`/api/scheduler/services/${serviceId}/status`);
}

export function fetchSchedulerRuns(
	serviceId: string,
	limit = 20,
): Promise<SchedulerRunsResponse> {
	return get<SchedulerRunsResponse>(
		`/api/scheduler/services/${serviceId}/runs`,
		{ limit: String(limit) },
	);
}

export function fetchSchedulerSamples(
	serviceId: string,
	windowSeconds: number,
): Promise<SchedulerSamplesResponse> {
	return get<SchedulerSamplesResponse>(
		`/api/scheduler/services/${serviceId}/samples`,
		{ window_seconds: String(windowSeconds) },
	);
}

export function runSchedulerAction(
	serviceId: string,
): Promise<SchedulerManualRunResponse> {
	return post<SchedulerManualRunResponse>(
		`/api/scheduler/services/${serviceId}/run`,
	);
}
