import { join } from "node:path";
import { mkdir, readFile, writeFile } from "node:fs/promises";

//#region src/deploy/LocalStateProvider.ts
/**
* Get the state file path for a stage.
*/
function getStateFilePath(workspaceRoot, stage) {
	return join(workspaceRoot, ".gkm", `deploy-${stage}.json`);
}
/**
* Local filesystem state provider.
*
* Stores state in .gkm/deploy-{stage}.json files in the workspace root.
*/
var LocalStateProvider = class {
	constructor(workspaceRoot) {
		this.workspaceRoot = workspaceRoot;
	}
	async read(stage) {
		const filePath = getStateFilePath(this.workspaceRoot, stage);
		try {
			const content = await readFile(filePath, "utf-8");
			return JSON.parse(content);
		} catch (error) {
			if (error.code === "ENOENT") return null;
			console.warn(`Warning: Could not read deploy state: ${error}`);
			return null;
		}
	}
	async write(stage, state) {
		const filePath = getStateFilePath(this.workspaceRoot, stage);
		const dir = join(this.workspaceRoot, ".gkm");
		await mkdir(dir, { recursive: true });
		state.lastDeployedAt = (/* @__PURE__ */ new Date()).toISOString();
		await writeFile(filePath, JSON.stringify(state, null, 2));
	}
};

//#endregion
export { LocalStateProvider };
//# sourceMappingURL=LocalStateProvider-Dp0KkRcw.mjs.map