import { logger } from "../../../logger/index.js";
import { ExternalHostError } from "../../../types/errors/external-host-error.js";
import { PRESET_DEP_NOT_FOUND, fetchPreset, parsePreset } from "../util.js";
import { getRepoContents } from "../../../modules/platform/gitea/gitea-helper.js";
//#region lib/config/presets/gitea/index.ts
const Endpoint = "https://gitea.com/";
async function fetchJSONFile(repo, fileName, endpoint, tag) {
	let res;
	try {
		res = await getRepoContents(repo, fileName, tag, { baseUrl: endpoint });
	} catch (err) {
		if (err instanceof ExternalHostError) throw err;
		logger.debug(`Preset file ${fileName} not found in ${repo}: ${err.message}`);
		throw new Error(PRESET_DEP_NOT_FOUND);
	}
	return parsePreset(res.contentString, fileName);
}
function getPresetFromEndpoint(repo, filePreset, presetPath, endpoint = Endpoint, tag) {
	return fetchPreset({
		repo,
		filePreset,
		presetPath,
		endpoint,
		tag,
		fetch: fetchJSONFile
	});
}
function getPreset({ repo, presetName = "default", presetPath, tag }) {
	return getPresetFromEndpoint(repo, presetName, presetPath, Endpoint, tag);
}
//#endregion
export { Endpoint, fetchJSONFile, getPreset, getPresetFromEndpoint };

//# sourceMappingURL=index.js.map