import { useApiClient } from "./useApi.js";
import { c } from "react/compiler-runtime";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
function usePipeline(n) {
	let i = c(10), { envKey: a, api: s } = useApiClient(), l;
	i[0] !== a || i[1] !== n ? (l = [
		"pipeline",
		n,
		a
	], i[0] = a, i[1] = n, i[2] = l) : l = i[2];
	let u;
	i[3] !== s || i[4] !== n ? (u = () => {
		if (!s) throw Error("API not available");
		return s.ApiV1PipelinesApi.pipelineControllerGetPipelineById({ id: n });
	}, i[3] = s, i[4] = n, i[5] = u) : u = i[5];
	let d = !!n, f;
	return i[6] !== l || i[7] !== u || i[8] !== d ? (f = {
		queryKey: l,
		queryFn: u,
		enabled: d,
		select: _temp
	}, i[6] = l, i[7] = u, i[8] = d, i[9] = f) : f = i[9], useQuery(f);
}
function _temp(e) {
	return e.data;
}
function useFilterPipelines(n, i, a, o, s, d) {
	let f = c(23), p = a === void 0 ? "id" : a, m = o === void 0 ? "DESC" : o, h = s === void 0 ? 0 : s, g = d === void 0 ? 10 : d, { envKey: _, api: v } = useApiClient(), y = Object.values(i).some(_temp2), b;
	f[0] !== i || f[1] !== y ? (b = y && { filter: JSON.stringify(i) }, f[0] = i, f[1] = y, f[2] = b) : b = f[2];
	let x;
	f[3] !== m || f[4] !== p ? (x = JSON.stringify([{
		field: p,
		order: m
	}]), f[3] = m, f[4] = p, f[5] = x) : x = f[5];
	let S;
	f[6] === n ? S = f[7] : (S = n && {
		search: n,
		searchColumns: JSON.stringify(["title", "model"])
	}, f[6] = n, f[7] = S);
	let C;
	f[8] !== g || f[9] !== h || f[10] !== b || f[11] !== x || f[12] !== S ? (C = {
		...b,
		sortBy: x,
		page: h,
		limit: g,
		...S
	}, f[8] = g, f[9] = h, f[10] = b, f[11] = x, f[12] = S, f[13] = C) : C = f[13];
	let w = C, T;
	f[14] !== _ || f[15] !== w ? (T = [
		"pipelines",
		w,
		_
	], f[14] = _, f[15] = w, f[16] = T) : T = f[16];
	let E;
	f[17] !== v || f[18] !== w ? (E = () => {
		if (!v) throw Error("API not available");
		return v.ApiV1PipelinesApi.pipelineControllerGetPipelines(w);
	}, f[17] = v, f[18] = w, f[19] = E) : E = f[19];
	let D;
	return f[20] !== T || f[21] !== E ? (D = {
		queryKey: T,
		queryFn: E,
		select: _temp3,
		enabled: !0
	}, f[20] = T, f[21] = E, f[22] = D) : D = f[22], useQuery(D);
}
function _temp3(e) {
	return e.data;
}
function _temp2(e) {
	return e != null;
}
function useCreatePipeline() {
	let r = c(8), { envKey: a, api: o } = useApiClient(), s = useQueryClient(), l;
	r[0] === o ? l = r[1] : (l = (e) => {
		if (!o) throw Error("API not available");
		return o.ApiV1PipelinesApi.pipelineControllerCreatePipeline(e);
	}, r[0] = o, r[1] = l);
	let u;
	r[2] !== a || r[3] !== s ? (u = () => {
		s.invalidateQueries({ queryKey: ["pipelines", a] });
	}, r[2] = a, r[3] = s, r[4] = u) : u = r[4];
	let d;
	return r[5] !== l || r[6] !== u ? (d = {
		mutationFn: l,
		onSuccess: u
	}, r[5] = l, r[6] = u, r[7] = d) : d = r[7], useMutation(d);
}
function usePipelineConfig(n, i) {
	let a = c(12), { envKey: o, api: s } = useApiClient(), l;
	a[0] !== o || a[1] !== i || a[2] !== n ? (l = [
		"pipelineConfig",
		n,
		i,
		o
	], a[0] = o, a[1] = i, a[2] = n, a[3] = l) : l = a[3];
	let u;
	a[4] !== s || a[5] !== i || a[6] !== n ? (u = () => {
		if (!s) throw Error("API not available");
		return s.ApiV1ConfigApi.configControllerGetPipelineConfigByName({
			workspaceBlockName: n,
			pipelineName: i
		});
	}, a[4] = s, a[5] = i, a[6] = n, a[7] = u) : u = a[7];
	let d = !!n && !!i, f;
	return a[8] !== l || a[9] !== u || a[10] !== d ? (f = {
		queryKey: l,
		queryFn: u,
		enabled: d,
		select: _temp4
	}, a[8] = l, a[9] = u, a[10] = d, a[11] = f) : f = a[11], useQuery(f);
}
function _temp4(e) {
	return e.data;
}
function useBatchDeletePipeline() {
	let r = c(7), { api: a } = useApiClient(), o = useQueryClient(), s;
	r[0] === a ? s = r[1] : (s = (e) => {
		if (!a) throw Error("API not available");
		return a.ApiV1PipelinesApi.pipelineControllerBatchDeletePipelines({ pipelineControllerBatchDeletePipelinesRequest: { ids: e } });
	}, r[0] = a, r[1] = s);
	let l;
	r[2] === o ? l = r[3] : (l = () => {
		o.invalidateQueries({
			queryKey: ["pipelines"],
			type: "all"
		});
	}, r[2] = o, r[3] = l);
	let u;
	return r[4] !== s || r[5] !== l ? (u = {
		mutationFn: s,
		onSuccess: l
	}, r[4] = s, r[5] = l, r[6] = u) : u = r[6], useMutation(u);
}
function useChildPipelines(n, i) {
	let a = c(10), { envKey: o, api: s } = useApiClient(), l;
	a[0] !== o || a[1] !== n ? (l = [
		"pipelines",
		"children",
		n,
		o
	], a[0] = o, a[1] = n, a[2] = l) : l = a[2];
	let u;
	a[3] !== s || a[4] !== n ? (u = () => {
		if (!s) throw Error("API not available");
		return s.ApiV1PipelinesApi.pipelineControllerGetPipelines({
			filter: JSON.stringify({ parentId: n }),
			sortBy: JSON.stringify([{
				field: "createdAt",
				order: "ASC"
			}]),
			page: 0,
			limit: 100
		});
	}, a[3] = s, a[4] = n, a[5] = u) : u = a[5];
	let d = i && !!n, f;
	return a[6] !== l || a[7] !== u || a[8] !== d ? (f = {
		queryKey: l,
		queryFn: u,
		enabled: d,
		select: _temp5
	}, a[6] = l, a[7] = u, a[8] = d, a[9] = f) : f = a[9], useQuery(f);
}
function _temp5(e) {
	return e.data;
}
function usePipelineSource(n, i) {
	let a = c(12), { envKey: o, api: s } = useApiClient(), l;
	a[0] !== o || a[1] !== i || a[2] !== n ? (l = [
		"pipelineSource",
		n,
		i,
		o
	], a[0] = o, a[1] = i, a[2] = n, a[3] = l) : l = a[3];
	let u;
	a[4] !== s || a[5] !== i || a[6] !== n ? (u = () => {
		if (!s) throw Error("API not available");
		return s.ApiV1ConfigApi.configControllerGetPipelineSourceByName({
			workspaceBlockName: n,
			pipelineName: i
		});
	}, a[4] = s, a[5] = i, a[6] = n, a[7] = u) : u = a[7];
	let d = !!n && !!i, f;
	return a[8] !== l || a[9] !== u || a[10] !== d ? (f = {
		queryKey: l,
		queryFn: u,
		enabled: d,
		select: _temp6
	}, a[8] = l, a[9] = u, a[10] = d, a[11] = f) : f = a[11], useQuery(f);
}
function _temp6(e) {
	return e.data;
}
export { useBatchDeletePipeline, useChildPipelines, useCreatePipeline, useFilterPipelines, usePipeline, usePipelineConfig, usePipelineSource };
