import { requireOptionalNativeModule } from 'expo-modules-core' export type EasyTierConfigInput = { networkName: string networkSecret: string peerUrls: string[] } type NativeModule = { isAvailable: () => boolean saveAndPrepareTunnel: (configJson: string) => Promise> checkVpnPermissionGranted: () => Promise> } const Native = requireOptionalNativeModule('ExpoEasyTierVpn') export function isExpoEasyTierVpnAvailable(): boolean { try { return Native?.isAvailable?.() === true } catch { return false } } export async function saveAndPrepareTunnel(config: EasyTierConfigInput): Promise> { if (!Native?.saveAndPrepareTunnel) { return { ok: false, reason: 'native_module_missing' } } return Native.saveAndPrepareTunnel(JSON.stringify(config)) } export async function checkVpnPermissionGranted(): Promise { if (!Native?.checkVpnPermissionGranted) return false const r = await Native.checkVpnPermissionGranted() return r?.granted === true }