/**
 * Supported MoQ Transport protocol versions
 */
export const Version = {
	/**
	 * draft-ietf-moq-transport-07
	 * https://www.ietf.org/archive/id/draft-ietf-moq-transport-07.txt
	 */
	DRAFT_07: 0xff000007,

	/**
	 * draft-ietf-moq-transport-14
	 * https://www.ietf.org/archive/id/draft-ietf-moq-transport-14.txt
	 */
	DRAFT_14: 0xff00000e,

	/**
	 * draft-ietf-moq-transport-15
	 * https://www.ietf.org/archive/id/draft-ietf-moq-transport-15.txt
	 */
	DRAFT_15: 0xff00000f,

	/**
	 * draft-ietf-moq-transport-16
	 * https://www.ietf.org/archive/id/draft-ietf-moq-transport-16.txt
	 */
	DRAFT_16: 0xff000010,

	/**
	 * draft-ietf-moq-transport-17
	 * https://www.ietf.org/archive/id/draft-ietf-moq-transport-17.txt
	 */
	DRAFT_17: 0xff000011,

	/**
	 * draft-ietf-moq-transport-18
	 * https://www.ietf.org/archive/id/draft-ietf-moq-transport-18.txt
	 */
	DRAFT_18: 0xff000012,

	/**
	 * draft-ietf-moq-transport-19
	 * https://www.ietf.org/archive/id/draft-ietf-moq-transport-19.txt
	 */
	DRAFT_19: 0xff000013,
} as const;

export type Version = (typeof Version)[keyof typeof Version];

// ALPN / WebTransport subprotocol identifiers for draft versions.
export const ALPN = {
	DRAFT_14: "moq-00",
	DRAFT_15: "moqt-15",
	DRAFT_16: "moqt-16",
	DRAFT_17: "moqt-17",
	DRAFT_18: "moqt-18",
	DRAFT_19: "moqt-19",
} as const;

/**
 * IETF protocol versions used by the ietf/ module.
 * Use this narrower type for version-branched encode/decode to get exhaustive matching.
 */
export type IetfVersion =
	| typeof Version.DRAFT_14
	| typeof Version.DRAFT_15
	| typeof Version.DRAFT_16
	| typeof Version.DRAFT_17
	| typeof Version.DRAFT_18
	| typeof Version.DRAFT_19;

const VERSION_NAMES: Record<number, string> = {
	[Version.DRAFT_07]: "moq-transport-07",
	[Version.DRAFT_14]: "moq-transport-14",
	[Version.DRAFT_15]: "moq-transport-15",
	[Version.DRAFT_16]: "moq-transport-16",
	[Version.DRAFT_17]: "moq-transport-17",
	[Version.DRAFT_18]: "moq-transport-18",
	[Version.DRAFT_19]: "moq-transport-19",
};

export function versionName(v: Version): string {
	return VERSION_NAMES[v] ?? `unknown(0x${v.toString(16)})`;
}
