import type { RuntimePlatform } from './platform-detection.rules';

export type MobileMediaPermissionState = 'granted' | 'denied' | 'prompt' | string;

export interface MobileCapturePermissionResult {
  microphone?: MobileMediaPermissionState;
  camera?: MobileMediaPermissionState;
}

/** Whether a Capacitor permission alias was granted by the native shell. */
export function isMobileCapturePermissionGranted(state: MobileMediaPermissionState | undefined): boolean {
  return state === 'granted';
}

/** Native Android/iOS shells need an explicit runtime grant before WebRTC capture works reliably. */
export function shouldPreflightMobileCapturePermissions(runtime: RuntimePlatform): boolean {
  return runtime === 'capacitor';
}

/** Resolve whether voice capture can proceed after a native permission request. */
export function isVoiceCaptureAllowed(result: MobileCapturePermissionResult): boolean {
  return isMobileCapturePermissionGranted(result.microphone);
}

/** Resolve whether camera capture can proceed after a native permission request. */
export function isCameraCaptureAllowed(result: MobileCapturePermissionResult): boolean {
  return isMobileCapturePermissionGranted(result.camera);
}
