import { apiGet, apiPost } from '@/lib/http'
import type { AdminScheduledJobsConfig, AdminScheduledJobsResponse } from '@/types/admin'

export function fetchAdminScheduledJobsConfig() {
  return apiGet<AdminScheduledJobsResponse>('/api/v1/admin/platform-config/scheduled-jobs')
}

export function saveAdminScheduledJobsConfig(payload: AdminScheduledJobsConfig) {
  return apiPost<AdminScheduledJobsResponse>(
    '/api/v1/admin/platform-config/scheduled-jobs',
    payload,
  )
}

export function runAdminScheduledJob(jobId: string) {
  return apiPost<{
    result: Record<string, unknown>
    runtime: AdminScheduledJobsResponse['runtime']
  }>(`/api/v1/admin/platform-config/scheduled-jobs/${jobId}/run`, {})
}
