import { readFileSync } from "node:fs";

export type SqlGPQuery = {
	query: string;
	success: boolean;
	message: string;
};

export const sqlGpQuerySelector = (name: string) => {
	try {
		const queryFile = readFileSync(
			new URL(`../gpSql/queries/${name}.sql`, import.meta.url),
			"utf8",
		);

		return {
			success: true,
			message: `Query for: ${name}`,
			query: queryFile,
		};
	} catch (e) {
		console.error(e);
		return {
			success: false,
			message:
				"Error getting the query file, please make sure you have the correct name.",
		};
	}
};
