// 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 }),
	getWslConfig: () => __TAURI_INVOKE<WslConfig>("get_wsl_config"),
	setWslConfig: (config: WslConfig) => __TAURI_INVOKE<null>("set_wsl_config", { config }),
	getDisplayBackend: () => __TAURI_INVOKE<"wayland" | "auto" | null>("get_display_backend"),
	setDisplayBackend: (backend: LinuxDisplayBackend) => __TAURI_INVOKE<null>("set_display_backend", { backend }),
	parseMarkdownCommand: (markdown: string) => __TAURI_INVOKE<string>("parse_markdown_command", { markdown }),
	checkAppExists: (appName: string) => __TAURI_INVOKE<boolean>("check_app_exists", { appName }),
	wslPath: (path: string, mode: "windows" | "linux" | null) => __TAURI_INVOKE<string>("wsl_path", { path, mode }),
	resolveAppPath: (appName: string) => __TAURI_INVOKE<string | null>("resolve_app_path", { appName }),
	openPath: (path: string, appName: string | null) => __TAURI_INVOKE<null>("open_path", { path, appName }),
};

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

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

export type LinuxDisplayBackend = "wayland" | "auto";

export type LoadingWindowComplete = null;

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

export type SqliteMigrationProgress = { type: "InProgress"; value: number } | { type: "Done" };

export type WslConfig = {
		enabled: boolean,
	};

export type WslPathMode = "windows" | "linux";

/* 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);
}

