//#region src/tunnel/tunnel-persist.ts
function persistedFromRegistration(registration) {
	return {
		tunnelId: registration.tunnelId,
		tunnelToken: registration.tunnelToken,
		subdomain: registration.subdomain,
		publicUrl: registration.publicUrl,
		frpcAuthToken: registration.frpc.authToken,
		registeredAt: (/* @__PURE__ */ new Date()).toISOString(),
		enabled: true,
		frpcServerAddr: registration.frpc.serverAddr,
		frpcServerPort: registration.frpc.serverPort,
		proxyName: registration.frpc.proxyName,
		heartbeatIntervalMs: registration.heartbeatIntervalMs
	};
}
/** Rebuild registration from disk when Broker row is still valid (stop without deregister). */
function registrationFromPersisted(persisted) {
	if (!persisted.frpcAuthToken || !persisted.frpcServerAddr || !persisted.frpcServerPort || !persisted.proxyName) return null;
	return {
		tunnelId: persisted.tunnelId,
		tunnelToken: persisted.tunnelToken,
		subdomain: persisted.subdomain,
		publicUrl: persisted.publicUrl,
		frpc: {
			serverAddr: persisted.frpcServerAddr,
			serverPort: persisted.frpcServerPort,
			authToken: persisted.frpcAuthToken,
			proxyName: persisted.proxyName
		},
		expiresAt: "",
		heartbeatIntervalMs: persisted.heartbeatIntervalMs ?? 3e4
	};
}
function canResumePersistedTunnel(persisted) {
	return Boolean(persisted?.tunnelId && persisted.tunnelToken && persisted.subdomain && persisted.frpcAuthToken && registrationFromPersisted(persisted));
}
//#endregion
export { canResumePersistedTunnel, persistedFromRegistration, registrationFromPersisted };

//# sourceMappingURL=tunnel-persist.js.map