import { useApi } from "./api.js";
export const DRIVER = { Wia: "Wia", Twain: "Twain", Sane: "Sane", Escl: "Escl" };
export const PAPER_SOURCE = { Auto: "Auto", Flatbed: "Flatbed", Feeder: "Feeder", Duplex: "Duplex" };
export const BIT_DEPTH = { Color: "Color", Grayscale: "Grayscale", BlackAndWhite: "BlackAndWhite" };
export const PRINT_DATA_TYPE = { Pdf: "Pdf", Image: "Image", Text: "Text", Html: "Html", Office: "Office" };
export function useHostAgent() {
  const api = useApi();
  const base = ["agent"];
  function getSettings(cache = false) {
    return api.getPromise([...base, "api/settings"], void 0, void 0, void 0, cache);
  }
  function updateSettings(settings) {
    return api.postPromise([...base, "api/settings"], settings);
  }
  function getPrinters(cache = false) {
    return api.getPromise([...base, "api/devices/printers"], void 0, void 0, void 0, cache);
  }
  function getScanners(cache = false) {
    return api.getPromise([...base, "api/devices/scanners"], void 0, void 0, void 0, cache);
  }
  function getIdCardInfo(reader) {
    return api.getPromise([...base, "idcard/info"], void 0, reader ? { reader } : void 0);
  }
  function getIdCardInfoAndPhoto(reader) {
    return api.getPromise(
      [...base, "idcard/infoAndPhoto"],
      void 0,
      reader ? { reader } : void 0
    );
  }
  function getCitizenId(reader) {
    return api.getPromise([...base, "idcard/citizenId"], void 0, reader ? { reader } : void 0);
  }
  function getMachineInfo() {
    return api.getPromise([...base, "machine/info"]);
  }
  function print(req) {
    return api.postPromise([...base, "print"], req);
  }
  function scan(req) {
    return api.postPromise([...base, "scan"], req);
  }
  function getLogFiles(cache = false) {
    return api.getPromise([...base, "api/logs/files"], void 0, void 0, void 0, cache);
  }
  function tailLog(file, lines = 500) {
    return api.getPromise([...base, "api/logs/tail"], void 0, { file, lines });
  }
  function isProblemDetails(x) {
    return !!x && typeof x === "object" && ("title" in x || "status" in x || "detail" in x);
  }
  return {
    // enums/constants
    DRIVER,
    PAPER_SOURCE,
    BIT_DEPTH,
    PRINT_DATA_TYPE,
    // REST
    getSettings,
    updateSettings,
    getPrinters,
    getScanners,
    getIdCardInfo,
    getIdCardInfoAndPhoto,
    getCitizenId,
    getMachineInfo,
    print,
    scan,
    getLogFiles,
    tailLog,
    // util
    isProblemDetails
  };
}
