// This file has been generated by Tauri Specta. Do not edit this file manually.

import { invoke as __TAURI_INVOKE, Channel } from '@tauri-apps/api/core';
import * as __TAURI_EVENT from "@tauri-apps/api/event";

/** Commands */
export const commands = {
	killSidecar: () => __TAURI_INVOKE<void>("kill_sidecar"),
	installCli: () => __TAURI_INVOKE<string>("install_cli"),
	awaitInitialization: (events: Channel) => __TAURI_INVOKE<ServerReadyData>("await_initialization", { events }),
	getDefaultServerUrl: () => __TAURI_INVOKE<string | null>("get_default_server_url"),
	setDefaultServerUrl: (url: string | null) => __TAURI_INVOKE<null>("set_default_server_url", { url }),
	parseMarkdownCommand: (markdown: string) => __TAURI_INVOKE<string>("parse_markdown_command", { markdown }),
	checkAppExists: (appName: string) => __TAURI_INVOKE<boolean>("check_app_exists", { appName }),
};

/** Events */
export const events = {
	loadingWindowComplete: makeEvent<LoadingWindowComplete>("loading-window-complete"),
};

/* Types */
export type InitStep = { phase: "server_waiting" } | { phase: "sqlite_waiting" } | { phase: "done" };

export type LoadingWindowComplete = null;

export type ServerReadyData = {
		url: string,
		password: string | null,
	};

/* Tauri Specta runtime */
function makeEvent<T>(name: string) {
    const base = {
        listen: (cb: __TAURI_EVENT.EventCallback<T>) => __TAURI_EVENT.listen(name, cb),
        once: (cb: __TAURI_EVENT.EventCallback<T>) => __TAURI_EVENT.once(name, cb),
        emit: (payload: T) => __TAURI_EVENT.emit(name, payload) as unknown as (T extends null ? () => Promise<void> : (payload: T) => Promise<void>)
    };

    const fn = (target: import("@tauri-apps/api/webview").Webview | import("@tauri-apps/api/window").Window) => ({
        listen: (cb: __TAURI_EVENT.EventCallback<T>) => target.listen(name, cb),
        once: (cb: __TAURI_EVENT.EventCallback<T>) => target.once(name, cb),
        emit: (payload: T) => target.emit(name, payload) as unknown as (T extends null ? () => Promise<void> : (payload: T) => Promise<void>)
    });

    return Object.assign(fn, base);
}

