import { requestClient } from '#/api/request';

export namespace ScheduleApi {
  export interface Schedule {
    [key: string]: any;
    name: string;
    params: string;
    invoke_target: string;
    cron_expression: string;
    enabled: boolean;
    last_execute_at: string;
    next_execute_at: string;
    execute_count: number;
    success_count: number;
    failed_count: number;
    remark: string;
    created_at: string;
    updated_at: string;
  }
  export interface getScheduleList {
    list: (Schedule & { id: string })[];
    total: number;
    current_page: number;
  }
  export interface createSchedule {
    name: string;
    org_id: string;
    cron_expression: string;
  }
  export interface updateSchedule {
    name: string;
    cron_expression: string;
  }
}
/**
 *
 * @param org_id
 * @param page
 * @param page_size
 * @returns
 */
export const getScheduleList = (
  org_id: string,
  page?: number,
  page_size?: number,
) => {
  return requestClient.get<ScheduleApi.Schedule>(
    '/device-management/cron_jobs',
    {
      params: {
        org_id,
        page,
        page_size,
      },
    },
  );
};
/**
 *
 * @param data
 * @returns
 */
export const createSchedule = (data: ScheduleApi.createSchedule) => {
  return requestClient.post('/device-management/cron_jobs', data);
};

/**
 *
 * @param id
 * @returns
 */
export const deleteSchedule = (id: string) => {
  return requestClient.delete(`/device-management/cron_jobs/${id}`);
};

export const updateSchedule = (
  id: string,
  data: ScheduleApi.updateSchedule,
) => {
  return requestClient.put(`/device-management/cron_jobs/${id}`, data);
};
