import { publicApi } from './http'

export async function fetchSchedules(params = {}) {
  const { data } = await publicApi.get('/schedules', { params })
  return data
}

export async function createSchedule(payload) {
  const { data } = await publicApi.post('/schedules', payload)
  return data
}

export async function updateSchedule(scheduleId, payload) {
  const { data } = await publicApi.put(`/schedules/${scheduleId}`, payload)
  return data
}

export async function deleteSchedule(scheduleId) {
  const { data } = await publicApi.delete(`/schedules/${scheduleId}`)
  return data
}

export async function toggleSchedule(scheduleId, payload) {
  const { data } = await publicApi.post(`/schedules/${scheduleId}/toggle`, payload)
  return data
}

export async function runScheduleNow(scheduleId) {
  const { data } = await publicApi.post(`/schedules/${scheduleId}/run`, {})
  return data
}

export async function fetchScheduleLogs(scheduleId, params = {}) {
  const { data } = await publicApi.get(`/schedules/${scheduleId}/logs`, { params })
  return data
}

export async function clearScheduleLogs(scheduleId) {
  const { data } = await publicApi.delete(`/schedules/${scheduleId}/logs`)
  return data
}
