import { executeQuery } from "~/lib/db";
import helper from "~/functions/helper";
import cache from "~/functions/cache";

async function getList() {
	const cachekey = "statusList";

	let list = null;

	if (cache.has(cachekey)) {
		list = cache.get(cachekey);
	} else {
		const rows = await executeQuery({
			query: `
			SELECT
				statusID,
				IFNULL(statusName, '') AS statusName,
				sortOrder
			FROM
				status
			ORDER BY
				sortOrder
		`,
		});

		list = helper.emptyOrRows(rows);

		cache.set(cachekey, list);
	}

	return list;
}

export default {
	getList,
};
