import { pages, structuredData } from "@ax/api";
import { isReqOk } from "@ax/helpers";
import { IPage, IStructuredDataContent } from "@ax/types";

const getPageSchemaVersion = async (id: number) => {
	try {
		const result = await pages.getPageInfo(id);
		if (result && isReqOk(result.status)) {
			const page: IPage = result.data;
			return page.schemaVersionTimestamp;
		}
	} catch (e) {
		console.log(e);
	}
	return undefined;
};

const getContentTypeSchemaVersion = async (id: number) => {
	try {
		const result = await structuredData.getDataContent(id, null);
		if (result && isReqOk(result.status)) {
			const data: IStructuredDataContent = result.data;
			return data.schemaVersionTimestamp;
		}
	} catch (e) {
		console.log(e);
	}
	return undefined;
};

export { getPageSchemaVersion, getContentTypeSchemaVersion };
