/** Core updates: signed release catalog (SHA-512 + OpenPGP), download and installer hand-off. */
import { call, subscribe } from "../transport";
import type { Payload } from "../types";

export const updates = Object.freeze({
  getState: () => call<Payload>("core_updates_get_state", "updates:getState"),
  check: () => call<Payload>("core_updates_check", "updates:check"),
  select: (id: string) => call<Payload>("core_updates_select", "updates:select", { id }),
  download: () => call<Payload>("core_updates_download", "updates:download"),
  install: () => call<{ ok: true; installed: boolean; restarting: boolean }>("core_updates_install", "updates:install"),
  reveal: () => call<{ ok: true }>("core_updates_reveal", "updates:reveal"),
  onState: (callback: (state: Payload) => void) => subscribe("core:updateState", callback)
});
