import { _ as isValidVarName } from "./transformers-DzHGqYO2.js";
import { t as camelCase } from "./casing-BSeq_teY.js";

//#region src/utils/uniqueName.ts
function getUniqueName(originalName, data) {
	let used = data[originalName] || 0;
	if (used) {
		data[originalName] = ++used;
		originalName += used;
	}
	data[originalName] = 1;
	return originalName;
}
function setUniqueName(originalName, data) {
	let used = data[originalName] || 0;
	if (used) {
		data[originalName] = ++used;
		return originalName;
	}
	data[originalName] = 1;
	return originalName;
}

//#endregion
//#region src/utils/URLPath.ts
var URLPath = class {
	path;
	#options;
	constructor(path, options = {}) {
		this.path = path;
		this.#options = options;
		return this;
	}
	/**
	* Convert Swagger path to URLPath(syntax of Express)
	* @example /pet/{petId} => /pet/:petId
	*/
	get URL() {
		return this.toURLPath();
	}
	get isURL() {
		try {
			if (new URL(this.path)?.href) return true;
		} catch (_error) {
			return false;
		}
		return false;
	}
	/**
	* Convert Swagger path to template literals/ template strings(camelcase)
	* @example /pet/{petId} => `/pet/${petId}`
	* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
	* @example /account/userID => `/account/${userId}`
	*/
	get template() {
		return this.toTemplateString();
	}
	get object() {
		return this.toObject();
	}
	get params() {
		return this.getParams();
	}
	toObject({ type = "path", replacer, stringify } = {}) {
		const object = {
			url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
			params: this.getParams()
		};
		if (stringify) {
			if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
			if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
			return `{ url: '${object.url}' }`;
		}
		return object;
	}
	/**
	* Convert Swagger path to template literals/ template strings(camelcase)
	* @example /pet/{petId} => `/pet/${petId}`
	* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
	* @example /account/userID => `/account/${userId}`
	*/
	toTemplateString({ prefix = "", replacer } = {}) {
		const found = this.path.match(/{(\w|-)*}/g);
		let newPath = this.path.replaceAll("{", "${");
		if (found) newPath = found.reduce((prev, path) => {
			const pathWithoutBrackets = path.replaceAll("{", "").replaceAll("}", "");
			let param = isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : camelCase(pathWithoutBrackets);
			if (this.#options.casing === "camelcase") param = camelCase(param);
			return prev.replace(path, `\${${replacer ? replacer(param) : param}}`);
		}, this.path);
		return `\`${prefix}${newPath}\``;
	}
	getParams(replacer) {
		const found = this.path.match(/{(\w|-)*}/g);
		if (!found) return;
		const params = {};
		found.forEach((item) => {
			item = item.replaceAll("{", "").replaceAll("}", "");
			let param = isValidVarName(item) ? item : camelCase(item);
			if (this.#options.casing === "camelcase") param = camelCase(param);
			const key = replacer ? replacer(param) : param;
			params[key] = key;
		}, this.path);
		return params;
	}
	/**
	* Convert Swagger path to URLPath(syntax of Express)
	* @example /pet/{petId} => /pet/:petId
	*/
	toURLPath() {
		return this.path.replaceAll("{", ":").replaceAll("}", "");
	}
};

//#endregion
export { getUniqueName as n, setUniqueName as r, URLPath as t };
//# sourceMappingURL=URLPath-BYceu_vY.js.map