import client from "./client";

export interface SyncMitreResponse {
  message: string;
  status?: string;
  new?: number;
  updated?: number;
}

export interface IntelScanResponse {
  message: string;
  new_items: number;
}

export interface SchedulerJob {
  id: string;
  name: string;
  next_run_time: string | null;
}

export interface SchedulerStatusResponse {
  running: boolean;
  jobs: SchedulerJob[];
}

/** Manually trigger MITRE ATT&CK sync. */
export async function triggerMitreSync(): Promise<SyncMitreResponse> {
  const { data } = await client.post<SyncMitreResponse>("/system/sync-mitre");
  return data;
}

/** Manually trigger threat intelligence scan. */
export async function triggerIntelScan(): Promise<IntelScanResponse> {
  const { data } = await client.post<IntelScanResponse>("/system/run-intel-scan");
  return data;
}

/** Get scheduler status. */
export async function getSchedulerStatus(): Promise<SchedulerStatusResponse> {
  const { data } = await client.get<SchedulerStatusResponse>("/system/scheduler-status");
  return data;
}
