/** * Admin Scheduled Tests API endpoints * Handles scheduled test plan management for account connectivity monitoring */ import { apiClient } from '../client' import type { ScheduledTestPlan, ScheduledTestResult, CreateScheduledTestPlanRequest, UpdateScheduledTestPlanRequest } from '@/types' /** * List all scheduled test plans for an account * @param accountId - Account ID * @returns List of scheduled test plans */ export async function listByAccount(accountId: number): Promise { const { data } = await apiClient.get( `/admin/accounts/${accountId}/scheduled-test-plans` ) return data ?? [] } /** * Create a new scheduled test plan * @param req - Plan creation request * @returns Created plan */ export async function create(req: CreateScheduledTestPlanRequest): Promise { const { data } = await apiClient.post( '/admin/scheduled-test-plans', req ) return data } /** * Update an existing scheduled test plan * @param id - Plan ID * @param req - Fields to update * @returns Updated plan */ export async function update(id: number, req: UpdateScheduledTestPlanRequest): Promise { const { data } = await apiClient.put( `/admin/scheduled-test-plans/${id}`, req ) return data } /** * Delete a scheduled test plan * @param id - Plan ID */ export async function deletePlan(id: number): Promise { await apiClient.delete(`/admin/scheduled-test-plans/${id}`) } /** * List test results for a plan * @param planId - Plan ID * @param limit - Optional max number of results to return * @returns List of test results */ export async function listResults(planId: number, limit?: number): Promise { const { data } = await apiClient.get( `/admin/scheduled-test-plans/${planId}/results`, { params: limit ? { limit } : undefined } ) return data ?? [] } export const scheduledTestsAPI = { listByAccount, create, update, delete: deletePlan, listResults } export default scheduledTestsAPI