const require_chunk = require('./chunk-CUT6urMc.cjs');
const node_path = require_chunk.__toESM(require("node:path"));
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));

//#region src/deploy/LocalStateProvider.ts
/**
* Get the state file path for a stage.
*/
function getStateFilePath(workspaceRoot, stage) {
	return (0, node_path.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 (0, node_fs_promises.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 = (0, node_path.join)(this.workspaceRoot, ".gkm");
		await (0, node_fs_promises.mkdir)(dir, { recursive: true });
		state.lastDeployedAt = (/* @__PURE__ */ new Date()).toISOString();
		await (0, node_fs_promises.writeFile)(filePath, JSON.stringify(state, null, 2));
	}
};

//#endregion
exports.LocalStateProvider = LocalStateProvider;
//# sourceMappingURL=LocalStateProvider-CLifRC0Y.cjs.map