// @ts-nocheck
// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.

/** user-defined commands **/


export const commands = {
async getWorkspaceInfo() : Promise<Result<WorkspaceInfo, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("get_workspace_info") };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async listDatasets(options: DatasetListOptions | null) : Promise<Result<DatasetInfo[], ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("list_datasets", { options }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async listDatasetTags() : Promise<Result<string[], ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("list_dataset_tags") };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async datasetDetail(id: number) : Promise<Result<DatasetDetail, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("dataset_detail", { id }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async datasetChartData(id: number, options: DatasetChartDataOptions) : Promise<Result<ChartDataResponse, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("dataset_chart_data", { id, options }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async getFilterTableData(id: number, options: FilterTableOptions) : Promise<Result<TableData, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("get_filter_table_data", { id, options }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async updateDatasetFavorite(id: number, update: DatasetFavoriteUpdate) : Promise<Result<null, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("update_dataset_favorite", { id, update }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async updateDatasetInfo(id: number, update: DatasetInfoUpdate) : Promise<Result<null, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("update_dataset_info", { id, update }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async getDatasetWriteStatus(id: number) : Promise<Result<DatasetWriteStatus, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("get_dataset_write_status", { id }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async deleteDatasets(ids: number[]) : Promise<Result<DatasetDeleteResult[], ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("delete_datasets", { ids }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async trashDatasets(ids: number[]) : Promise<Result<DatasetDeleteResult[], ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("trash_datasets", { ids }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async restoreDatasets(ids: number[]) : Promise<Result<DatasetDeleteResult[], ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("restore_datasets", { ids }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async emptyTrash() : Promise<Result<DatasetDeleteResult[], ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("empty_trash") };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async batchUpdateDatasetTags(update: BatchTagUpdateOptions) : Promise<Result<DatasetTagBatchResult[], ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("batch_update_dataset_tags", { update }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async deleteTag(tag: string) : Promise<Result<null, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("delete_tag", { tag }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async renameTag(oldName: string, newName: string) : Promise<Result<null, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("rename_tag", { oldName, newName }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async mergeTag(source: string, target: string) : Promise<Result<null, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("merge_tag", { source, target }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async exportDatasetsDialog(ids: number[]) : Promise<Result<string[] | null, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("export_datasets_dialog", { ids }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async previewImportDialog() : Promise<Result<UiPreviewImportResult[] | null, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("preview_import_dialog") };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async previewImportFiles(paths: string[]) : Promise<Result<UiPreviewImportResult[], ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("preview_import_files", { paths }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
},
async importDataset(archivePath: string, force: boolean) : Promise<Result<DatasetInfo, ApiError>> {
    try {
    return { status: "ok", data: await TAURI_INVOKE("import_dataset", { archivePath, force }) };
} catch (e) {
    if(e instanceof Error) throw e;
    else return { status: "error", error: e  as any };
}
}
}

/** user-defined events **/


export const events = __makeEvents__<{
datasetCreated: DatasetCreated,
datasetUpdated: DatasetUpdated
}>({
datasetCreated: "dataset-created",
datasetUpdated: "dataset-updated"
})

/** user-defined constants **/



/** user-defined types **/

export type ApiError = { code: ApiErrorCode; message: string }
export type ApiErrorCode = "dataset_not_found" | "dataset_deleted" | "dataset_not_trashed" | "archive_version_unsupported" | "invalid_tag" | "same_tag_name" | "same_source_target" | "workspace" | "charts" | "dialog" | "validation" | "internal"
export type BatchTagUpdateOptions = { ids: number[]; add?: string[] | null; remove?: string[] | null }
export type ChartDataResponse = { type: ChartType; xName: string; yName: string | null; xCategories: number[] | null; yCategories: number[] | null; series: Series[] }
export type ChartType = "line" | "heatmap" | "scatter"
export type ColumnInfo = { name: string; isComplex: boolean; isTrace: boolean; isIndex: boolean }
export type ColumnUniqueValue = { index: number; displayValue: string }
export type ComplexViewOption = "real" | "imag" | "mag" | "arg"
export type DatasetChartDataOptions = ({ chartType: "line" } & LineChartDataOptions) | ({ chartType: "heatmap" } & HeatmapChartDataOptions) | ({ chartType: "scatter" } & ScatterChartDataOptions)
export type DatasetCreated = DatasetInfo
export type DatasetDeleteResult = { id: number; success: boolean; error: DatasetOperationError | null }
export type DatasetDetail = { id: number; name: string; description: string; favorite: boolean; tags: string[]; status: UiDatasetStatus; createdAt: string; trashedAt: string | null; deletedAt: string | null; payloadAvailable: boolean; columns: ColumnInfo[] }
export type DatasetFavoriteUpdate = { favorite: boolean }
export type DatasetInfo = { id: number; name: string; description: string; favorite: boolean; tags: string[]; status: UiDatasetStatus; createdAt: string; trashedAt: string | null; deletedAt: string | null }
export type DatasetInfoUpdate = { name?: string | null; description?: string | null; favorite?: boolean | null; tags?: string[] | null }
export type DatasetListOptions = { search?: string | null; tags?: string[] | null; favoriteOnly?: boolean | null; statuses?: UiDatasetStatus[] | null; trashed?: boolean | null; sortBy?: UiDatasetSortBy | null; sortDir?: UiSortDirection | null; limit?: number | null; offset?: number | null }
export type DatasetOperationError = { code: ApiErrorCode; message: string }
export type DatasetTagBatchResult = { id: number; success: boolean; addError: DatasetOperationError | null; removeError: DatasetOperationError | null }
export type DatasetUpdated = DatasetInfo
export type DatasetWriteStatus = { rowCount: number; isComplete: boolean }
export type FilterTableOptions = { excludeColumns?: string[] | null }
export type HeatmapChartDataOptions = ({ start: number | null; end: number | null; indexFilters: number[] | null; excludeColumns: string[] | null }) & { series: string; xColumn: string | null; yColumn: string; complexViewSingle: ComplexViewOption | null }
export type LineChartDataOptions = ({ start: number | null; end: number | null; indexFilters: number[] | null; excludeColumns: string[] | null }) & { series: string; xColumn: string | null; complexViews: ComplexViewOption[] | null }
export type Row = { displayValues: string[]; valueIndices: number[]; index: number }
export type ScatterChartDataOptions = ({ start: number | null; end: number | null; indexFilters: number[] | null; excludeColumns: string[] | null }) & { scatter: ScatterModeOptions }
export type ScatterModeOptions = { mode: "complex"; series: string } | { mode: "trace_xy"; traceXColumn: string; traceYColumn: string } | { mode: "xy"; xColumn: string; yColumn: string; binColumn: string | null }
export type Series = { name: string; data: number[][] }
export type TableData = { fields: string[]; rows: Row[]; columnUniqueValues: Partial<{ [key in string]: ColumnUniqueValue[] }> }
export type UiDatasetSortBy = "id" | "name" | "createdAt"
export type UiDatasetStatus = "Writing" | "Completed" | "Aborted"
export type UiExportedMetadata = { uid: string; name: string; description: string; favorite: boolean; status: UiDatasetStatus; createdAt: string; tags: string[] }
export type UiFieldDiff = { field: string; existingValue: string; incomingValue: string }
export type UiImportConflict = { existing: UiExportedMetadata; diffs: UiFieldDiff[] }
export type UiImportPreview = { metadata: UiExportedMetadata; conflict: UiImportConflict | null }
export type UiPreviewImportResult = { archivePath: string; preview: UiImportPreview }
export type UiSortDirection = "asc" | "desc"
export type WorkspaceInfo = { path: string }

/** tauri-specta globals **/

import {
	invoke as TAURI_INVOKE,
	Channel as TAURI_CHANNEL,
} from "@tauri-apps/api/core";
import * as TAURI_API_EVENT from "@tauri-apps/api/event";
import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow";

type __EventObj__<T> = {
	listen: (
		cb: TAURI_API_EVENT.EventCallback<T>,
	) => ReturnType<typeof TAURI_API_EVENT.listen<T>>;
	once: (
		cb: TAURI_API_EVENT.EventCallback<T>,
	) => ReturnType<typeof TAURI_API_EVENT.once<T>>;
	emit: null extends T
		? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit>
		: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>;
};

export type Result<T, E> =
	| { status: "ok"; data: T }
	| { status: "error"; error: E };

function __makeEvents__<T extends Record<string, any>>(
	mappings: Record<keyof T, string>,
) {
	return new Proxy(
		{} as unknown as {
			[K in keyof T]: __EventObj__<T[K]> & {
				(handle: __WebviewWindow__): __EventObj__<T[K]>;
			};
		},
		{
			get: (_, event) => {
				const name = mappings[event as keyof T];

				return new Proxy((() => {}) as any, {
					apply: (_, __, [window]: [__WebviewWindow__]) => ({
						listen: (arg: any) => window.listen(name, arg),
						once: (arg: any) => window.once(name, arg),
						emit: (arg: any) => window.emit(name, arg),
					}),
					get: (_, command: keyof __EventObj__<any>) => {
						switch (command) {
							case "listen":
								return (arg: any) => TAURI_API_EVENT.listen(name, arg);
							case "once":
								return (arg: any) => TAURI_API_EVENT.once(name, arg);
							case "emit":
								return (arg: any) => TAURI_API_EVENT.emit(name, arg);
						}
					},
				});
			},
		},
	);
}
