import { execFileSync } from "node:child_process";
import { defaultPlugins, defineConfig } from "@hey-api/openapi-ts";

const openApiInput = `${execFileSync("portless", ["get", "zerobyte"], { encoding: "utf8" }).trim().replace(/\/$/, "")}/api/v1/openapi.json`;

export default defineConfig({
	input: openApiInput,
	output: {
		path: "./app/client/api-client",
		header: ["// @ts-nocheck", "// This file is auto-generated by @hey-api/openapi-ts"],
		postProcess: [
			{
				command: "vp",
				args: ["fmt", "--write", "{{path}}"],
			},
			{ command: "bun", args: ["scripts/patch-api-client.ts"] },
		],
	},
	plugins: [...defaultPlugins, "@tanstack/react-query", "@hey-api/client-fetch"],
});
