// The global sync engine: overall status, pause/resume, and a manual subscriptions pull.
// (Per-channel management + my-status/deep-all live in channels.ts.) Only touches core's req.
import { req } from "./core";

export interface SyncStatus {
  subscriptions: number;
  channels_total: number;
  channels_backfilling: number;
  videos_total: number;
  pending_enrich: number;
  quota_used_today: number;
  quota_remaining_today: number;
  paused: boolean;
  is_admin: boolean;
}

export const syncApi = {
  status: (): Promise<SyncStatus> => req("/api/sync/status"),
  pauseSync: () => req("/api/sync/pause", { method: "POST" }),
  resumeSync: () => req("/api/sync/resume", { method: "POST" }),
  syncSubscriptions: (): Promise<{
    subscriptions: number;
    channels_new: number;
    channels_detailed: number;
    removed_stale: number;
    prune_skipped: boolean;
    quota_used_estimate: number;
    quota_remaining_today: number;
  }> => req("/api/sync/subscriptions", { method: "POST" }),
};
